标题:
[转帖]得到perl原始时间格式的函数
[打印本页]
作者:
cnangel
时间:
2004-4-2 00:31
标题:
[转帖]得到perl原始时间格式的函数
作者:bigjim
得到perl原始时间格式的函数如下代码:
[font=宋体]sub gettime
{#取得指定时间Unix时间戳, CopyRight 94Cool.Net BigJim
my ($year, $month, $day, $hour, $minute) = @_;
my $nowtime = time;
my ($nowsecond, $nowminute, $nowhour, $nowday, $nowmonth, $nowyear, undef) = localtime($nowtime);
$nowmonth++;
$nowyear += 1900;
my @monthdays = (0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334);
@monthdays = (0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335) if ($year % 4 == 0);
my @nowmonthdays = (0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334);
@nowmonthdays = (0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335) if ($nowyear % 4 == 0);
my $betweendays = ($year - $nowyear) * 365 + ($monthdays[$month] - $nowmonthdays[$nowmonth]) + ($day - $nowday) + int(($year - $nowyear + 1) / 4);
return $nowtime + $betweendays * 86400 + ($hour - $nowhour) * 3600 + ($minute - $nowminute) * 60 - $nowsecond;
}[/font]
复制代码
欢迎光临 星星博客 (http://bbs.huhoo.net/)
Powered by Discuz! 7.0.0