[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [leafnode-list] [ANNOUNCE:] leafnode-1.9.12
> Joerg Dietrich wrote:
>
> I guess I am completely confused now. I tried the following
example
> program. It gets the time in seconds since the epoch into a
structure
> and converts it back into seconds since the epoch.
Unfortunately, it
> apparently doesn't work (i.e. it appears that time() returns
seconds
> since the epoch in "localtime" instead of UTC) or I got my brain
in a
No, time(0) returns UTC. The following will print UTC unless
your system clock is wrong:
#include "stdio.h"
#include "stdlib.h"
#include "time.h"
main(){
time_t now=time(0);
putenv("TZ=GMT0"); // ignored by time(), used by ctime()
puts( ctime(&now));
}
It's mktime that expects local time in the tm struct and returns
UTC seconds.
Your test program works fine here. I added the line
printf( "timezone appears to be GMT%d\n", (age-now)/(60*60) );
and it printed out the right numeric offset. Notice that the
offset is calculated in the reverse order, from local to UTC
rather than the expected order. <shrug>
--
Oisin "Curly++" Curtin ocurtin@SPAM@usa.net
Surface Liaison, Minetown Digger Send no SPAM@
http://pages.infinit.net/curlypp/
--
leafnode-list@xxxxxxxxxxxxxxxxxxxxxxxxxxxx -- mailing list for leafnode
To unsubscribe, send mail with "unsubscribe" in the subject to the list