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 婆婆高寿祝福语大全简短