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 生日开业蛋糕祝福语简短