如何在perl中轉換1461241125.31307。我想:如何將perix中的unix時代轉換爲可讀格式
use Date::Parse;
$unix_timestamp = '1461241125.31307';
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime($unix_timestamp);
$mon += 1;
$year += 1900;
$unix_timestamp_normal = "$year-$mon-$mday $hour:$min:$sec";
結果:2016-4-21 5:18:45
(小時沒有填充)
我怎麼墊並使其GMT。我想要結果說2016-04-21 12:18:45
感謝您的答案人。
use DateTime;
$unix_timestamp = '1461241125.31307';
my $dt = DateTime->from_epoch(epoch => $unix_timestamp);
print $dt->strftime('%Y-%m-%d %H:%M:%S'),"\n";
使用POSIX的strftime比使用多更輕便DateTime的(而且是核心) – ikegami