目的: 將 1262785521 轉換成人類可以看得懂的時間格式為 2010-01-06 21:45:21

1262785521 是從 1970-01-01 至現在所經過的秒數

程式:

use strict;
my $time = time;
my ($sec,$min,$hour,$day,$month,$year) = (localtime($time))[0,1,2,3,4,5,6];
$month++;
$year+=1900;
if (length($sec) == 1) {$sec = “0”.”$sec”;}
if (length($min) == 1) {$min = “0”.”$min”;}
if (length($hour) == 1) {$hour = “0”.”$hour”;}
if (length($day) == 1) {$day = “0”.”$day”;}
if (length($month) == 1) {$month = “0”.”$month”;}

print “Convert $time to $year-$month-$day $hour:$min:$sec”;

參考:
http://www.epochconverter.com/epoch/functions-perl.php
http://www.epochconverter.com/

Related posts 相關文章
2020 年迎來了 PHP 8 與 Perl 7
More...
安裝 perl 5.8.1 版本 – 草記
More...
perl 備註
More...
perl 隨機產生 password 密碼
More...

作者

留言

撰寫回覆或留言

發佈留言必須填寫的電子郵件地址不會公開。