Print Date

P

pandit

Hello :)
I am here Scuh a long time. i just want to print Date (Day of the
month) on the Screen i googling and Seach Archive i found it
but i dont know how this is to be used boz i need the system date(day)
or some Purpose

here is code i get from a web-site.
i am confuse about it
#include<ctime>
inr main()
{
time_t tt;
struct tm *tod; // why we use it?
time(&tt);
tod =localtime(&tt); //and also use?
std :: cout <<tod->tm_mon+1;
std:: cout<<std::endl;
exit(0);
}


whu we need struct here
please tell me.

Thanks
 
V

Victor Bazarov

pandit said:
Hello :)
I am here Scuh a long time.
"Scuh"?

> i just want to print Date (Day of the
month) on the Screen i googling and Seach Archive i found it
but i dont know how this is to be used boz i need the system date(day)
or some Purpose

here is code i get from a web-site.
i am confuse about it
#include<ctime>

You forget to include said:
inr main()

Don't re-type your code. Use "copy-and-paste" capabilities of your
computer.
{
time_t tt;
struct tm *tod; // why we use it?

This is called a "declaration". The 'struct' keyword is superfluous in
this case.
time(&tt);
tod =localtime(&tt); //and also use?

You're obtaining a pointer to the struct from the function. Now the
pointer points to some memory area in the system memory where the value
of 'tt' is broken into components.
std :: cout <<tod->tm_mon+1;
std:: cout<<std::endl;
exit(0);
}


whu we need struct here

Not sure what exactly your question is.

V
 
P

Pandit

Thanks V.
Mine question is that i have to get the day from the system date
because i have a other function that will do somthing for evryday(for
exp at the day 1st of the month it will check something and display
somthing and 2nd say somthing different and so on).
But when we use time(&tt) then what it will do.

how time work's?
 
V

Victor Bazarov

Pandit said:
Mine question is that i have to get the day from the system date
because i have a other function that will do somthing for evryday(for
exp at the day 1st of the month it will check something and display
somthing and 2nd say somthing different and so on).

That's not a question, by the way.
But when we use time(&tt) then what it will do.

how time work's?

'time' works in mysterious ways. Somehow, could be by the built-in
black magic, the call to 'time' sets the value of 'tt' (passed by the
address as the argument) to be such that when it's used later in
'localtime', the struct tm will have human-understandable values filled
in to correspond to the system time at the moment of the call to 'time'
function.

Some systems will have 'tt' as the number of seconds elapsed from some
designated time (like IBM PC/XT used to have 1st of January, 1980, and
Unix systems have 1st of January, 1970), but you don't need to know
that, do you? You just need to know that 'tt' is set to some value that
represents the current system clock, and you can later use it in
'localtime' to get the time represented by year, month, day, hour, etc.

V
 
P

Pandit

That's not a question, by the way.



'time' works in mysterious ways.  Somehow, could be by the built-in
black magic, the call to 'time' sets the value of 'tt' (passed by the
address as the argument) to be such that when it's used later in
'localtime', the struct tm will have human-understandable values filled
in to correspond to the system time at the moment of the call to 'time'
function.

Some systems will have 'tt' as the number of seconds elapsed from some
designated time (like IBM PC/XT used to have 1st of January, 1980, and
Unix systems have 1st of January, 1970), but you don't need to know
that, do you?  You just need to know that 'tt' is set to some value that
represents the current system clock, and you can later use it in
'localtime' to get the time represented by year, month, day, hour, etc.

V

Thanks Victor now i find my all answers about it.
 
J

James Kanze

Mine question is that i have to get the day from the system
date because i have a other function that will do somthing
for evryday(for exp at the day 1st of the month it will check
something and display somthing and 2nd say somthing different
and so on). But when we use time(&tt) then what it will do.

The function time gets the system's opinion of the date and
time, in a encoded format: time_t is an arithmetic
type---typically an integral type containing the number of
seconds since some defined epoch.

The function localtime takes a time_t, and breaks it down in the
year/month/day/hours/minutes/seconds. The results are in a
structure called tm.

I'd suggest that you read the documentation for the two
functions.
how time work's?

That's the system's problem, not yours. (Formally, it's not
even required to work; it may systematically return
(time_t)(-1). But in practice, that's not likely to be a
problem on general purpose machines.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,828
Latest member
LauraCastr

Latest Threads

Top