Time Zone - Day Light Savings


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Time Zone - Day Light Savings
# 1  
Old 08-24-2007
Time Zone - Day Light Savings

Our system has an option to supply your timezone in area of world you want to keep time for user transactions and such.

It keeps time zone for user in database as for example -5 for EST.

The problem is we are in EDT -4 (daylight savings time) so the time is displayed wrong.

We can put the time in the system in a standard UNIXTIMESTAMP format but when we convert with most perl functions like time2str it does not take into account daylight savings time.

Does anybody know a solution or point me in right direction. We use linux and perl, but any programming language will do.

tks
# 2  
Old 08-24-2007
For my solution see: Understanding Unix Timekeeping

If you don't like my solution and decide to ask for another, tell us what OS you are using.
# 3  
Old 08-27-2007
DateTime module did the job very well.

Here is an example.

Code:
#! /usr/bin/perl
use Time::Local;

($s,$min,$h,$d,$m,$y,$dst) = (localtime)[0,1,2,3,4,5,8];
$m +=1;
$y += 1900;

########################################
use DateTime;

$dt = DateTime->new(
			year => $y,
			month => $m,
			day => $d,
			hour => $h,
			minute => $min,
			second => $s,
			nanosecond => 500000000,
			time_zone => 'America/New_York',
		);
$dt->set_time_zone('UTC');
print $dt->datetime; 
print $dt->time_zone_short_name;
print "\n";
$dt->set_time_zone('America/New_York');
print $dt->datetime;
print $dt->time_zone_short_name;
print "\n";
$dt->set_time_zone('America/Chicago');
print $dt->datetime;
print $dt->time_zone_short_name;
print "\n";

The output is:

Code:
2007-08-27T23:18:50UTC
2007-08-27T19:18:50EDT
2007-08-27T18:18:50CDT

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Solaris

showing 2 different time zones in global zone and nonglobal zone

can some one help me out as it is showing 2 different time zones in global zone and nonglobal zone .In global zone it is showing in GMT while in nonglobal zone i it showing as PDT. System in running with solaris 10 (3 Replies)
Discussion started by: ravijanjanam12
3 Replies

2. UNIX for Advanced & Expert Users

Auto resetting for Daylight Savings Time

We have an ancient Unix box from Siemens. Every year the system automatically changes the time for EST or DST. Unfortunately since the box is so old the dates that the times change are the old dates and not the current ones set during (I think) the Bush years. When I have to set the time back... (3 Replies)
Discussion started by: jbcamel
3 Replies

3. Shell Programming and Scripting

Date increment issue due to day light saving

The date increment worked fine until date reached 25/10, which is DLS change date. /bin/date --date="091025 1 day" +%y%m%d; the output is 091025 Is this a bug or something missing from the code ! (3 Replies)
Discussion started by: rajbravo
3 Replies

4. AIX

Daylight savings time

Hello everyone The last sunday I have to check that my servers has change Daylight savings time but only two servers do it and all the rest doesnt. In smitty where I need to change, for my server take automatic the daylight savings time. Thanks for your tips The next its a message for... (0 Replies)
Discussion started by: lo-lp-kl
0 Replies

5. AIX

Daylight savings time

Our aix unix box did not recognize daylight savings time since it was moved up. Could someone please give me the syntax to change the hour? I looked in man and couldn't find anything, or I missed it. I'm in 3rd grade so if you can, please provide specific instructions. Thanks! (2 Replies)
Discussion started by: vbagwell
2 Replies

6. AIX

Day Light Savings Time problem

Hi guys, OS: AIX 5.3.0.0 I'm from Portugal and I had problems about Day Light changing time, the hour's changes in first Sunday of November, but it's wrong because in Europe the day light need to change in last Sunday of October. My TZ is TZ=GMT0BST, that I think BST it's British Summer Time. I... (2 Replies)
Discussion started by: uadm26
2 Replies

7. UNIX for Dummies Questions & Answers

Day light savings

Does anyone know how to reset a network printer to allow for the daylight savings?:) (0 Replies)
Discussion started by: Tweedy
0 Replies

8. Solaris

Daylight Savings Time Quirk

I am running a SUN E450 on solaris (5.7). I have applied the DST patch and the system time is correct. However when users login the get the time wrong (+4 hours) (I am in EDT Zone). Does anyone know where a system wide variable for this could be set. (Root user gets the right time) Frank (3 Replies)
Discussion started by: frankkahle
3 Replies

9. Solaris

Daylight Savings Time Fix

Hello, I've been looking at coming up with a time change on my Sun workstations since daylight savings time comes early this year. Someone at work told me that a sun patch is available if you have a maintenance contract. It was recommended to just set your systems to GMT time zone. How is this... (5 Replies)
Discussion started by: stocksj
5 Replies
Login or Register to Ask a Question