当前位置: 动力学知识库 > 问答 > 编程问答 >

datetime format - error while converting IST date to EST date in perl

问题描述:

I am using the following code for changing the time from IST to EST... But Perl says "invalid offset : IST" and The timezone 'EST' could not be loaded, or is an invalid name.

Can any one please help?"

use DateTime;

use DateTime::Format::Strptime;

my $val = "20090103 12:00";

my $format = new DateTime::Format::Strptime(

pattern => '%Y%m%d %H:%M',

time_zone => 'IST', );

my $date = $format->parse_datetime($val);

print $date->strftime("%Y%m%d %H:%M %Z")."\n";

$date->set_time_zone('EST');

print $date->strftime("%Y%m%d %H:%M %Z")."\n";

网友答案:

According to this site, IST is used for several countries:

IST Israel Standard Time    Asia    UTC + 2 hours
IST India  Standard Time    Asia    UTC + 5:30 hours
IST Irish  Standard Time    Europe  UTC + 1 hour

So, instead of using IST, use for example Europe/Dublin

网友答案:

Use an Olson DB time zone names like "Asia/Jerusalem" and "America/New_York" instead of "IST" aund "EST". You can look them up here.

See http://search.cpan.org/dist/DateTime-TimeZone/lib/DateTime/TimeZone.pm and http://en.wikipedia.org/wiki/Tz_database for details

网友答案:

Instead of IST, use the Olsen name of Asia/Kolkata.

分享给朋友:
您可能感兴趣的文章:
随机阅读: