目的: 將 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/
留言