Sponsored Content
Top Forums Shell Programming and Scripting Time Zone - Day Light Savings Post 302133968 by photon on Monday 27th of August 2007 09:30:12 PM
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

 

9 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

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

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

7. 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

8. 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

9. 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
DateTime::Format::Epoch::DotNet(3pm)			User Contributed Perl Documentation		      DateTime::Format::Epoch::DotNet(3pm)

NAME
DateTime::Format::Epoch::DotNet - Convert DateTimes to/from .NET epoch seconds SYNOPSIS
use DateTime::Format::Epoch::DotNet; my $dt = DateTime::Format::Epoch::DotNet->parse_datetime( 1051488000 ); DateTime::Format::Epoch::DotNet->format_datetime($dt); # 1051488000 my $formatter = DateTime::Format::Epoch::DotNet->new(); my $dt2 = $formatter->parse_datetime( 1051488000 ); $formatter->format_datetime($dt2); DESCRIPTION
This module can convert a DateTime object (or any object that can be converted to a DateTime object) to the number of seconds since the epoch defined in the .NET Framework SDK. Note that this epoch is defined in the local time zone. This means that these two pieces of code will print the same number of seconds, even though they represent two datetimes 6 hours apart: $dt = DateTime->new( year => 2003, month => 5, day => 2, time_zone => 'Europe/Amsterdam' ); print $formatter->format_datetime($dt); $dt = DateTime->new( year => 2003, month => 5, day => 2, time_zone => 'America/Chicago' ); print $formatter->format_datetime($dt); METHODS
Most of the methods are the same as those in DateTime::Format::Epoch. The only difference is the constructor. o new() Constructor of the formatter/parser object. It has no parameters. SUPPORT
Support for this module is provided via the datetime@perl.org email list. See http://lists.perl.org/ for more details. AUTHOR
Eugene van der Pijll <pijll@gmx.net> COPYRIGHT
Copyright (c) 2003 Eugene van der Pijll. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO
DateTime datetime@perl.org mailing list perl v5.10.1 2007-12-03 DateTime::Format::Epoch::DotNet(3pm)
All times are GMT -4. The time now is 10:16 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy