On 26 Aug 2003 07:18:46 -0700,
jd*******@yahoo.com (david) wrote:
tm = localtime(&ps->date);
printf("---------------------\n");
printf("Date: %d/%02d/%02d %02d:%02d:%02d\n",
1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday,
tm->tm_hour, tm->tm_min, tm->tm_sec);
...
The printout listed the time one hour off from GMT (probably due to
daylight saving..) instead in local time which is EDT.
The timezone for the platform (Linux Redhat8.0) seems to be setup
correctly. I try to set the TZ with different values, but the results
are for some reason not stable.
On the several platforms I have to hand at the moment (none of which are RH
8.0), daylight time offsets appear to be applied to the GMT, not to the
local time.
You may want to check a newsgroup devoted to your compiler and/or platform,
as tzset(), while a popular function, is not part of ANSI/ISO C.
That being said, compare this code with TZ=EST5EDT and TZ=EST5:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
time_t t;
struct tm *gmt, *lat;
tzset();
printf("Local timezone is TZ=%s\n\n", getenv("TZ"));
t = time(NULL);
lat = localtime(&t);
printf("Local time is : %s", asctime(lat));
gmt = gmtime(&t);
printf("GMT is : %s", asctime(gmt));
return 0;
}
Output:
C:\>set tz=EST5EDT
C:\>ltime
Local timezone is TZ=EST5EDT
Local time is : Tue Aug 26 12:27:19 2003
GMT is : Tue Aug 26 16:27:19 2003
C:\>set tz=EST5
C:\>ltime
Local timezone is TZ=EST5
Local time is : Tue Aug 26 12:27:26 2003
GMT is : Tue Aug 26 17:27:26 2003
C:\>
--
Robert B. Clark (email ROT13'ed)
Visit ClarkWehyr Enterprises On-Line at
http://www.3clarks.com/ClarkWehyr/