PDA

View Full Version : Placing the Current Time in a tm structure



WebmasterMattD
04-06-2002, 06:23 AM
Okay here is what I am trying to do.
I have included the time.h header which allows me to create tm structutes.

The beuty of using a tm structure is that it allows you to break down the time into years, months, days, hours, minutes, seconds and so on.

Now it would make things easier if i could just place the name that I called the structure equal to time() but that doesn't seem to work.

If anyone has a way of doing this it would be of greate help.

Buy the way it is a linux based program (obviously).

Later,

Salem
04-06-2002, 07:26 AM
If you want to turn a time() into a struct tm, use gmtime() or localtime()

Going the other way, it's mktime()

Read about them in your manual pages

WebmasterMattD
04-06-2002, 07:31 AM
Thanks dude.

I will try it out.

Later,

WebmasterMattD
04-06-2002, 08:20 AM
Okay tried that, works to some degree, though I am not getting the time from the computers clock when using *localtime() or *gmtime().

is there some argument that I am missing when calling these?

Later.

Salem
04-06-2002, 08:27 AM
time_t now = time(NULL);
struct tm *tnow = localtime( &now );
printf( "Day=%d\n", tnow->tm_mday );