Perl time 函式



說明

此函式返回自時間原點(大多數系統為 1970 年 1 月 1 日 00:00:00 UTC;Mac OS 為 1904 年 1 月 1 日 00:00:00)以來的秒數。適合傳給 gmtime 和 localtime。

語法

以下是此函式的簡單語法 −

time

返回值

此函式返回整數值,自紀元以來的秒數。

示例

以下是顯示其基本用法示例程式碼 −

#!/usr/bin/perl -w

@weekday = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");

$retval = time();

print "Return time is $retval\n";
$local_time = gmtime( $retval);

print "Local time = $local_time\n";
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time);
$year = $year + 1900;
$mon += 1;
print "Formated time = $mday/$mon/$year $hour:$min:$sec $weekday[$wday]\n";

執行以上程式碼將產生以下結果 −

Return time is 1176831539
Local time = Tue Apr 17 17:38:59 2007
Formated time = 17/4/2007 17:38:59 Tue
perl_function_references.htm
廣告
© . All rights reserved.