Perl的纪元时间
您可以在Perl中使用time()函数获取纪元时间,即自给定日期以来的秒数,在Unix中为1970年1月1日。
示例
#!/usr/local/bin/perl $epoc = time(); print "Number of seconds since Jan 1, 1970 - $epoc\n";
输出结果
执行以上代码后,将产生以下结果-
Number of seconds since Jan 1, 1970 - 1361022130
您可以将给定的秒数转换为日期和时间字符串,如下所示:
示例
#!/usr/local/bin/perl $datestring = localtime(); print "Current date and time $datestring\n"; $epoc = time(); $epoc = $epoc - 24 * 60 * 60; # one day before of current date. $datestring = localtime($epoc); print "Yesterday's date and time $datestring\n";
输出结果
执行以上代码后,将产生以下结果-
Current date and time Tue Jun 5 05:54:43 2018 Yesterday's date and time Mon Jun 4 05:54:43 2018
热门推荐
10 老师订婚文案祝福语简短
11 旅游景区新春祝福语简短
12 婆婆生娃祝福语简短
13 新年的鸡汤祝福语简短
14 喜欢新车的祝福语简短
15 乔迁仪式文案祝福语简短
16 上岸离职祝福语大全简短
17 年终企业送祝福语简短
18 六十岁大寿祝福语简短