The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Daylight savings time vbagwell AIX 2 03-11-2008 11:14 AM
Day Light Savings Time problem uadm26 AIX 2 11-07-2007 11:19 AM
Day light savings Tweedy UNIX for Dummies Questions & Answers 0 10-31-2007 12:37 PM
Daylight Savings Time Fix stocksj SUN Solaris 5 02-21-2007 12:17 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-24-2007
photon's Avatar
photon photon is offline
Registered User
  
 

Join Date: Jul 2002
Posts: 162
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 (permalink)  
Old 08-24-2007
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
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 (permalink)  
Old 08-27-2007
photon's Avatar
photon photon is offline
Registered User
  
 

Join Date: Jul 2002
Posts: 162
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:48 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0