转载自 http://www.cnblogs.com/starspace/archive/2008/12/17/1356672.html
#===============================================================
# get the current date,
# format is: YYYY-MM-DD HH(24):MM:SS
#===============================================================
sub getcurrdate
{
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $time) = localtime();
my $date;
$date = sprintf("%4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d",
$year + 1900, $mon + 1, $mday, $hour, $min, $sec);
return $date;
}
转载自 http://perldoc.perl.org/functions/localtime.html
1. 一般使用:
@nowtime=localtime();
#( $sec , $min , $hour , $mday , $mon , $year , $wday , $yday , $isdst ) = localtime();
注 意$mon+1,$year+1900;
$now_string = localtime; # e.g., "Thu Oct 13 04:54:34 1994"
2.如果要把时间保存在数据库中,可以先将其保存为字符串,然后读出时对字符串再处理。
@nowtime=localtime();
$nowstring=join(',',@nowtime);
将$nowstring保存;
读取的时候
@nowtime=split(',',$nowstring);