Operating System - HP-UX
1854909 Members
2738 Online
104105 Solutions
New Discussion

Re: Timezone and daylight savings time.

 
Jeff Gunnink
Advisor

Timezone and daylight savings time.

We have some jobs that need to kick off at a certain hour of the day regardless of the time change twice a year. Right now our TZ is PST8PDT. I was hoping that at the time change, the TZ variable would change to PST7PDT, then those writing jobs could query this and see that we are only 7 hours off GMT and compensate for it. But alas, after last weekend, 'echo $TZ' still gives PST8PDT. Is there any other way of finding out when we are 7 hours off vs 8 hours?
4 REPLIES 4
James R. Ferguson
Acclaimed Contributor

Re: Timezone and daylight savings time.

Hi Jeff:

The TZ variable defines the standard and daylight savings rules for your timezone, along with the number of hours that are added to universal time to arrive at local time. You don't have to change anything to accomodate the shift between standard and daylight times. Rather, these rules are pre-defined in /usr/lib/tztab.

Take a look at the man pages: 'environ (5)' and 'tztab (4)'.

'cron' (see 'man 1M cron') handles this transition between standard and daylight times without intervention too as described in its man pages.

...JRF...
Jeff Gunnink
Advisor

Re: Timezone and daylight savings time.

More info. I guess they have an app that queries the TZ variable to give the current UTC time back. Since the TZ variable did not change at the spring forward time, it is now reporting one hour off. I guess they need to look at the source to fix it.
Kenneth Platz
Esteemed Contributor

Re: Timezone and daylight savings time.

Jeff,

There are a number of different ways to determine the correct UTC time. The easiest way is to simply:

$ TZ=GMT date
Mon Apr 2 17:31:15 GMT 2001

Or to do this within a C program:

#include
#include
struct tm *timeg;
time_t timex;

timex = time( NULL );
timeg = gmtime( &timex );
printf( asctime( timeg ) );

This will then print out the current time in GMT. More information can be found in the man pages for time(2) and gmtime(3C).

I hope this helps.

I think, therefore I am... I think!
James R. Ferguson
Acclaimed Contributor

Re: Timezone and daylight savings time.

Hi Jeff:

To find out when you are seven, and when you are eight hours from UTC, you can use display the date (time) as Kenneth shows, or you can look in /usr/lib/tztab as I suggested above.

For instance, comparing my local time here in Florida to UTC:

# date;TZ=GMT date
Mon Apr 2 14:49:17 EDT 2001
Mon Apr 2 18:49:17 GMT 2001

Note the absence of the semicolon between 'TZ' and 'date'. This sets the TZ variable only for the second statement.

Alternately, if I look in /usr/lib/tztab for the rules govering by timezone (EST5EDT), I can see that during days 1-7 in April (the fourth month) during the years 1987-2038, I will be four (EDT4) hours from UTC in my "(D)aylight" time period. Then, in October when the day falls from 25-31 in the years 1975-2038 my time will be 5-hours from UTC.

Normally, the TZ variable is set during login when /etc/profile is read. The variable is set by sourcing /etc/TIMEZONE if that is readable and if not, it is set to MST7MDT in the default profile.

Perhaps this helps further.

...JRF...