Article View: gnu.gcc.help
Article #52450Timezone problem
From: "Hartmut W. Malzahn"
Date: Wed, 23 Sep 1992 22:06
Date: Wed, 23 Sep 1992 22:06
55 lines
2000 bytes
2000 bytes
I have a little problem with GCC, and I hope that someone can give me a
hint about it:
My local time is Central European Time, which is one hour ahead of British
time, and during daylight savings two hours ahead of GMT. So I set my TZ
variable to this:
TZ=CET-1CST
Now I should be able to get both local and GM time from GCC. The following
little program, however, doesn't work:
/----------------------
#include <stdio.h>
#include <time.h>
main ()
{
time_t now;
int hour_l,hour_g;
tzset ();
time (&now);
hour_l = localtime(&now)->tm_hour;
puts (asctime (localtime (&now)));
hour_g = gmtime(&now)->tm_hour;
puts (asctime (gmtime (&now)));
printf ("local: %i, gmt: %i\n",hour_l,hour_g);
}
\----------------------
The output from this is (when run at 00:04:35 local time):
/----------------------
Wed Sep 23 22:04:35 1992
Wed Sep 23 22:04:35 1992
local: 22, gmt: 22
\----------------------
So GCC treats the TZ variable correctly in that it evaluates the correct
GMT, and this also works for other zones and dates as well. So what am I
doing wrong that prevents localtime from giving me "00:04" instead of the
above?
---
| Hartmut Malzahn | CompuServe: 100012.1107@compuserve.com |
| Zimmerstrasse 9 | UK: hwm@hamster.demon.co.uk |
| W-5860 Iserlohn | |
| Germany | FAX: +49-2371-14491 |
Technical Details
Message-ID:
<717286018snx@hamster.demon.co.uk>Path:
arc1-ca.pugleaf.net!sparky!uunet!pipex!demon!hamster.demon.co.uk!hwmShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,3349eaa94956509a,start
X-Google-Attributes: gid11318c,public
X-Google-ArrivalTime: 1992-09-23 17:21:36 PST
Newsgroups: gnu.gcc.help
From: hwm@hamster.demon.co.uk ("Hartmut W. Malzahn")
Path: arc1-ca.pugleaf.net!sparky!uunet!pipex!demon!hamster.demon.co.uk!hwm
Subject: Timezone problem
Distribution: world
Organization: Maus Iserlohn
Lines: 55
Date: Wed, 23 Sep 1992 22:06:58 +0000
Message-ID: <717286018snx@hamster.demon.co.uk>
Sender: usenet@gate.demon.co.uk