perl localtime 時間隔式計算
作者: cross 日期: 2009-03-14 13:56
perl 使用 localtime 來算出現在系統時間,
底下作一個 func_date_time function
再拿一個值給 func_date_time 讓它顯示秒、分、時、日、月、年、週
use strict;
sub func_date_time {
my ($date_second,$date_minute,$date_hour,$date_day,$date_month,$date_year,$date_week)=localtime(time);
$date_month++;
$date_year+=1900;if (length($date_second) == 1) {$date_second = "0"."$date_second";}
if (length($date_minute) == 1) {$date_minute = "0"."$date_minute";}
if (length($date_hour) == 1) {$date_hour = "0"."$date_hour";}
if (length($date_day) == 1) {$date_day = "0"."$date_day";}
if (length($date_month) == 1) {$date_month = "0"."$date_month";}my $which_time = shift;
if ($which_time) {
if ($which_time =~ /second/) {
return $date_second;
} elsif ($which_time =~ /minute/){
return $date_minute;
} elsif ($which_time =~ /hour/){
return $date_hour;
} elsif ($which_time =~ /day/){
return $date_day;
} elsif ($which_time =~ /month/){
return $date_month;
} elsif ($which_time =~ /year/){
return $date_year;
} elsif ($which_time =~ /week/){
return $date_week;}
} else {
return "$date_year/$date_month/$date_day $date_hour:$date_minute:$date_second";
}
}print my $sec = func_date_time('second');
print " ";
print my $min = func_date_time('minute');
print " ";
print my $hr = func_date_time('hour');
print " ";
print my $day = func_date_time('day');
print " ";
print my $month = func_date_time('month');
print " ";
print my $year = func_date_time('year');
print " ";
print my $week = func_date_time('week');
上一篇
返回
下一篇
標籤:




perl 所謂的參照 (2011-08-02 23:59)
perl 的map功用 (2011-08-02 23:18)
perl 關於排序功能 (2011-08-02 22:41)
perl 如何輸入密碼時以星號*顯示 (2011-05-14 19:31)
perl 怎麼達到 ls 功能 (續) (2011-04-19 12:05)
perl 模組 - package範例 (2011-04-03 22:43)
編譯perl模組遇到的問題 (2011-03-07 16:27)
perl 一個可以學習怎麼寫CGI程式的地方 (2010-05-01 00:44)
perl 程式存取 MS Access MDB 資料庫 (續) UPDATE語法 (2010-03-12 10:58)