2011-04-24 54 views

回答

4
use DateTime; 
say "UTC:\t\t"  . DateTime->now->iso8601; 
say "London time:\t" . DateTime->now->set_time_zone("Europe/London")->iso8601; 

UTC:   2011-04-24T17:45:16 
London time: 2011-04-24T18:45:16 
+0

如何是从设定不同的'$ ENV {TZ}'为 “欧洲/伦敦”? – tchrist 2011-04-24 22:55:47

+1

@tchrist,我相信DateTime是线程安全的,'$ ENV {TZ}'方法不是。我怀疑他们使用tz数据库的不同来源。您可以使用DateTime在日期或时间戳上执行其他功能。 DateTime有许多解析器和格式器。 – ikegami 2011-04-25 05:14:18

+1

@tchrist,在Windows(也可能是其他平台)上,在程序启动后设置'$ ENV {TZ}'不起作用。只有初始值很重要。 – cjm 2011-04-25 15:48:53

0

使用DateTime模块。他们有各种日期和时间计算工具,包括时区支持。

Time Zones常见问题解答将帮助您了解常见的时区问题。

0

在标准的Perl:

% env TZ=Europe/London date 
Sun Apr 24 19:51:24 BST 2011 

% env TZ=Europe/London perl -le 'print scalar localtime' 
Sun Apr 24 19:51:37 2011 

% env TZ=Europe/London perl -MPOSIX=strftime -le 'print strftime "%x %X %Z (%z)", localtime' 
04/24/11 19:51:52 BST (+0100)