From: ftilley AT azstarnet DOT cyberbromo DOT com (Felix Tilley) Newsgroups: comp.os.msdos.djgpp Subject: strftime: Need Help with Time Offsets Date: Fri, 15 Dec 2000 07:07:52 GMT Organization: delete.spammers.org Message-ID: <3a39c060.1329770@corp.supernews.net> X-Newsreader: Forte Free Agent 1.21/32.243 X-Complaints-To: newsabuse AT supernews DOT com Lines: 120 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com This works fine under Linux Mandrake and some versions of HP-UX. It works under djgpp too, except for the GMT offsets. The strftime %z %Z formats do not appear to be uniform over the C/Unix/DOS/Linux environments. The program's output is first, very simple followed by the source code. PROGRAM OUTPUT: FET> FET> ./a.out Fri, 15 Dec 2000 07:01:31 +000 Fri, 15 Dec 2000 00:01:31 -000 Fri, 15 Dec 2000 02:01:31 -000 Fri, 15 Dec 2000 01:01:31 -000 Thu, 14 Dec 2000 23:01:31 -000 Fri, 15 Dec 2000 15:01:31 +288 FET> All of the GMT offsets are wrong. Dates and times are correct, but the GMT offsets are wrong. Source code is: /* Test of date formatting */ #include "stdio.h" #include "string.h" #include "stdlib.h" #include "time.h" main () { time_t tnum, tmpnum; struct tm *tmdate; char *sdate[256], *dstring; char *whatidstr="\n@(#) Prints Several TZ's 17 NOV 2000\n"; char *fmt= "%a, %d %b %Y %X %z %Z"; time(&tnum); /* Get Machine Time */ tmdate=gmtime(&tnum); /* Get and print GMT */ /* dstring=asctime(tmdate); printf("GMT\n%s", dstring); */ strftime( (char*) sdate, 200, fmt, tmdate); printf ("%s\n", sdate); tmdate=localtime(&tnum); /* Get and print local time */ /* dstring=asctime(tmdate); printf("LOCAL\n%s", dstring); */ strftime( (char*) sdate, 200, fmt, tmdate); printf ("%s <--\n", sdate); tmdate=gmtime(&tnum); /* GMT again */ tmdate->tm_hour=tmdate->tm_hour - 5; /* GMT -0500 EST */ tmdate->tm_gmtoff= -5*3600; tmdate->tm_zone="EST"; mktime (tmdate); tmdate->tm_gmtoff= -5*3600; tmdate->tm_zone="EST"; strftime( (char*) sdate, 200, fmt, tmdate); printf ("%s\n", sdate); tmdate=gmtime(&tnum); /* GMT again */ tmdate->tm_hour=tmdate->tm_hour - 6; /* GMT -0600 CST */ tmdate->tm_gmtoff= -6*3600; tmdate->tm_zone="CST"; mktime (tmdate); tmdate->tm_gmtoff= -6*3600; tmdate->tm_zone="CST"; strftime( (char*) sdate, 200, fmt, tmdate); printf ("%s\n", sdate); tmdate=gmtime(&tnum); /* GMT again */ tmdate->tm_hour=tmdate->tm_hour - 8; /* GMT -0800 PST */ tmdate->tm_gmtoff= -8*3600; tmdate->tm_zone="PST"; mktime (tmdate); tmdate->tm_gmtoff= -8*3600; tmdate->tm_zone="PST"; strftime( (char*) sdate, 200, fmt, tmdate); printf ("%s\n", sdate); tmdate=gmtime(&tnum); /* GMT again */ tmdate->tm_hour=tmdate->tm_hour + 8; /* GMT +0800 Beijing */ tmdate->tm_gmtoff= 8*3600; tmdate->tm_zone="BST"; mktime (tmdate); tmdate->tm_gmtoff= 8*3600; tmdate->tm_zone="BST"; strftime( (char*) sdate, 200, fmt, tmdate); printf ("%s\n", sdate); exit(0); } |----------------------------------| | Felix Tilley | | Remove Percent Signs for Email | | ftilley@%azstarnet.%%%com | |----------------------------------|