-1

我已经经历了很多答案,但似乎没有一个能解决我的问题。我想从纽约运行一个 Perl 脚本来在其他时区的计算机上安排任务,比如洛杉矶(或任何其他时区)。运行脚本的用户可以选择输入日期/时间和时区。

例子:

perl script.pl -action reboot LAHost.com 2014/012/12 15:00:00 'America/Los_Angeles'

此脚本应安排在洛杉矶当地时间下午 3 点在 LAHost.com 计算机上重新启动。

谁能帮我找到一种在 perl 中使用 DateTime 或任何其他内置函数的方法?

我是编程新手,目前正在学习 Perl。所以请原谅我的无知。

4

2 回答 2

0
my $timeZone="Europe/London";
my $dateTime = DateTime->new(year => $year, month => $month,
                day => $day, hour => $hour, minute => $minute,
                second => $second, time_zone => $timeZone);
于 2014-02-09T05:02:47.117 回答
0

你的问题似乎是

如何将指定时区的日期和时间转换为当地时间?

use DateTime::Format::Strptime qw( );

my $date = '2014/012/12';
my $time = '15:00:00';
my $tz   = 'America/Los_Angeles';

my $format = DateTime::Format::Strptime->new(
   pattern   => '%Y/%m/%d %H:%M:%S',
   time_zone => $tz,
   on_error  => 'croak',
);

my $dt = $format->parse_datetime("$date $time");
$dt->set_time_zone('local');

print $format->format_datetime($dt), "\n";
于 2014-02-08T18:10:14.500 回答