如何在Perl中获取日期时间中的当前时间
我正在编写一个Perl脚本,它以datetime格式获取当前时间。如何在Perl中以datetime格式将当前时间存储到变量中?您可以使用“localtime()”返回历元时间如何在Perl中获取日期时间中的当前时间,perl,datetime,timestamp,Perl,Datetime,Timestamp,我正在编写一个Perl脚本,它以datetime格式获取当前时间。如何在Perl中以datetime格式将当前时间存储到变量中?您可以使用“localtime()”返回历元时间 use strict; use warnings; use DateTime; my $dt = DateTime->now; # Stores current date and time as datetime object 您可以将其转换为字符串时间。如果那是你想要的 strftime("%Y
use strict;
use warnings;
use DateTime;
my $dt = DateTime->now; # Stores current date and time as datetime object
您可以将其转换为字符串时间。如果那是你想要的
strftime("%Y-%m-%d %H:%M:%S", localtime);
在标准POSIX模块中使用strftime:
$ perl -MPOSIX -le 'print strftime "%F %T", localtime $^T'
在Perl的绑定中,strftime的参数被设计为与localtime和gmtime的返回值对齐