-1

我正在编写一个以日期时间格式获取当前时间的 Perl 脚本。如何将当前时间存储到 Perl 中日期时间格式的变量中?

4

3 回答 3

3
use strict;
use warnings;
use DateTime;    
my $dt   = DateTime->now;   # Stores current date and time as datetime object
于 2013-05-28T12:22:15.273 回答
3

您可以使用“localtime()”返回 EPOCH 时间。

您可以将其转换为字符串时间。如果那是你想要的。

strftime("%Y-%m-%d %H:%M:%S", localtime);
于 2013-05-28T12:24:00.737 回答
1

在标准 POSIX 模块中使用strftime :

$ perl -MPOSIX -le 'print strftime "%F %T", localtime $^T'

Perl 绑定中strftime的参数旨在与localtimegmtime的返回值保持一致。

于 2013-05-28T17:17:07.767 回答