在Perl中,我想在特定时区查找本地时间.我一直在使用这种技术:
$ENV{TZ} = 'America/Los_Angeles';
my $now = scalar localtime;
print "It is now $now\n";
# WORKS: prints the current time in LA
Run Code Online (Sandbox Code Playgroud)
但是,这是不可靠的 - 特别是,如果我在设置$ ENV {TZ}之前添加另一个localtime()调用,它会中断:
localtime();
$ENV{TZ} = 'America/Los_Angeles';
my $now = scalar localtime;
print "It is now $now\n";
# FAILS: prints the current time for here instead of LA
Run Code Online (Sandbox Code Playgroud)
有一个更好的方法吗?
perl ×1