localtime() / time zone question 
Author Message
 localtime() / time zone question

I am trying to use the C function localtime() to convert UTC time to the
local time zone, including the conversion for daylight savings time.
However, localtime() is only converting to standard time in the local
time zone and is ignoring daylight savings time, contrary to what the
documentation implies.

I have read the man pages on Linux and Solaris as well as consulting
Stevens' book and the O'Reilly book UNIX Systems Programming for SVR4,
and I believe I am calling localtime() correctly.  Before the call, I
set the $ENV variable to :US/Pacific, which directs localtime() to
read the time zone information from the system files
/usr/share/zoneinfo (Linux) or /usr/share/lib/zoneinfo (Solaris).

Here is some sample input and output:
Time zone              UTC time                Local time
===================    ===================     ===================
:US/Pacific            2000  6  2  0  0  0     2000  6  1 16  0  0
:US/Pacific            2000 12  2  0  0  0     2000 12  1 16  0  0

Since this time zone uses daylight savings time and the changeover
occured this fall, the time shift to UTC should have changed by an
hour.

Any ideas?  This is gcc 2.95 on Linux 2.2.16, but I need a portable
solution,

Richard Anderson



Sat, 24 May 2003 03:00:00 GMT  
 localtime() / time zone question
I am attempting to use localtime() to convert from UTC to the
local time, including the correction for daylight savings time.
However, localtime() is only converting to the standard local
time and is ignoring daylight savings time.  I have consulted the
man pages on Linux and Solaris, as well as Stevens' book and the
O'Reilly book UNIX Systems Programming for SVR4 and I believe I
am calling localtime correctly.  Before the call I set the
environment variable TZ to ":US/Pacific".  According to the man
page for tzset, this reads the local time zone and daylight
savings time from the system time zone files (in
/usr/share/zoneinfo on Linux, /usr/share/lib/zoneinfo on Solaris).

Here is some input and output data for my call:
Time zone              UTC time                Local time        
===================    ===================     ===================
:US/Pacific            2000  6  2  0  0  0     2000  6  1 16  0  0
:US/Pacific            2000 12  2  0  0  0     2000 12  1 16  0  0

Since daylight savings time went into effect this fall, the time
shift between UTC and US/Pacific time should have changed by an
hour, but it is the same for both calls.

Does anyone have an idea about what I am doing wrong?  This is gcc
2.95 on Linux 2.2.16 (but I need a portable solution).

Richard Anderson


      [ about comp.lang.c++.moderated. First time posters: do this! ]



Sat, 24 May 2003 03:00:00 GMT  
 localtime() / time zone question
It sounds like your localtime() is working correctly because daylight
savings time is supposed to be used in summer - not in winter.


Quote:
> I am attempting to use localtime() to convert from UTC to the
> local time, including the correction for daylight savings time.
> However, localtime() is only converting to the standard local
> time and is ignoring daylight savings time.  I have consulted the
> man pages on Linux and Solaris, as well as Stevens' book and the
> O'Reilly book UNIX Systems Programming for SVR4 and I believe I
> am calling localtime correctly.  Before the call I set the
> environment variable TZ to ":US/Pacific".  According to the man
> page for tzset, this reads the local time zone and daylight
> savings time from the system time zone files (in
> /usr/share/zoneinfo on Linux, /usr/share/lib/zoneinfo on Solaris).

> Here is some input and output data for my call:
> Time zone              UTC time                Local time
> ===================    ===================     ===================
> :US/Pacific            2000  6  2  0  0  0     2000  6  1 16  0  0
> :US/Pacific            2000 12  2  0  0  0     2000 12  1 16  0  0

> Since daylight savings time went into effect this fall, the time
> shift between UTC and US/Pacific time should have changed by an
> hour, but it is the same for both calls.

> Does anyone have an idea about what I am doing wrong?  This is gcc
> 2.95 on Linux 2.2.16 (but I need a portable solution).

> Richard Anderson


>       [ about comp.lang.c++.moderated. First time posters: do this! ]



Sat, 24 May 2003 03:00:00 GMT  
 localtime() / time zone question
I sent a response to answer your question, but apparently the moderator
rejected my message. Sorry!


Quote:
> I am attempting to use localtime() to convert from UTC to the
> local time, including the correction for daylight savings time.
> However, localtime() is only converting to the standard local
> time and is ignoring daylight savings time.  I have consulted the
> man pages on Linux and Solaris, as well as Stevens' book and the
> O'Reilly book UNIX Systems Programming for SVR4 and I believe I
> am calling localtime correctly.  Before the call I set the
> environment variable TZ to ":US/Pacific".  According to the man
> page for tzset, this reads the local time zone and daylight
> savings time from the system time zone files (in
> /usr/share/zoneinfo on Linux, /usr/share/lib/zoneinfo on Solaris).

> Here is some input and output data for my call:
> Time zone              UTC time                Local time
> ===================    ===================     ===================
> :US/Pacific            2000  6  2  0  0  0     2000  6  1 16  0  0
> :US/Pacific            2000 12  2  0  0  0     2000 12  1 16  0  0

> Since daylight savings time went into effect this fall, the time
> shift between UTC and US/Pacific time should have changed by an
> hour, but it is the same for both calls.

> Does anyone have an idea about what I am doing wrong?  This is gcc
> 2.95 on Linux 2.2.16 (but I need a portable solution).

> Richard Anderson


>       [ about comp.lang.c++.moderated. First time posters: do this! ]



Mon, 26 May 2003 03:00:00 GMT  
 localtime() / time zone question
If my memory serves me right one element of the struct returned by
localtime is called tm_isdst if this is bigger than 0 just add 3600 to
the time_t ... Simple but hard to find ( I found in in the *.h file ).

Best regards

        Mario Loefler

Quote:

> I am attempting to use localtime() to convert from UTC to the
> local time, including the correction for daylight savings time.
> However, localtime() is only converting to the standard local
> time and is ignoring daylight savings time.  I have consulted the
> man pages on Linux and Solaris, as well as Stevens' book and the
> O'Reilly book UNIX Systems Programming for SVR4 and I believe I
> am calling localtime correctly.  Before the call I set the
> environment variable TZ to ":US/Pacific".  According to the man
> page for tzset, this reads the local time zone and daylight
> savings time from the system time zone files (in
> /usr/share/zoneinfo on Linux, /usr/share/lib/zoneinfo on Solaris).

> Here is some input and output data for my call:
> Time zone              UTC time                Local time
> ===================    ===================     ===================
> :US/Pacific            2000  6  2  0  0  0     2000  6  1 16  0  0
> :US/Pacific            2000 12  2  0  0  0     2000 12  1 16  0  0

> Since daylight savings time went into effect this fall, the time
> shift between UTC and US/Pacific time should have changed by an
> hour, but it is the same for both calls.

> Does anyone have an idea about what I am doing wrong?  This is gcc
> 2.95 on Linux 2.2.16 (but I need a portable solution).

> Richard Anderson


>       [ about comp.lang.c++.moderated. First time posters: do this! ]



Sat, 31 May 2003 23:21:44 GMT  
 localtime() / time zone question

Quote:
>If my memory serves me right one element of the struct returned by
>localtime is called tm_isdst if this is bigger than 0 just add 3600 to
>the time_t ... Simple but hard to find ( I found in in the *.h file ).

Not hard to find at all: it's documented in Appendix B of K&R2.

Dan
--
Dan Pop
CERN, IT Division

Mail:  CERN - IT, Bat. 31 1-014, CH-1211 Geneve 23, Switzerland



Sat, 31 May 2003 23:39:56 GMT  
 localtime() / time zone question
On Tue, 12 Dec 2000 16:21:44 +0100, Mario Loefler

Quote:

>If my memory serves me right one element of the struct returned by
>localtime is called tm_isdst if this is bigger than 0 just add 3600 to
>the time_t ... Simple but hard to find ( I found in in the *.h file ).

be warned tho that not all OS'es reliably mark this field, and of
course you are relying on the source machine being correctly set up.

--
Mark McIntyre
C- FAQ: http://www.eskimo.com/~scs/C-faq/top.html



Sun, 01 Jun 2003 08:20:53 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Problem with localtime and time zones

2. How to convert local time with specific time zone to UTC time in Win32 API

3. How to convert local time to gmt using a local variable time zone per process/thread

4. set date/time/time zone dialog

5. Real time From Time Zone information

6. Want to get localtime from GMT time...

7. Bugs in time(), localtime(), and CTime

8. Converting VARIANT DATE to GreenwichMean Time (GMT) or LocalTime

9. time() and localtime() on UNIX

10. Obtain Time Zone

11. Getting time zone information?

12. Time Zones

 

 
Powered by phpBB® Forum Software