注意:localtime获取的年份是相对于1900的偏移,需要加上1900,而localtime获取的month范围是0-11,需要加1。
实现代码如下:
#!/usr/bin/perl
my ($sec,$min,$hour,$day,$mon,$year,$wday,$yday,$isdst) = localtime();
$year += 1900;
$mon++;
my $date = "$year-$mon-$day";
print $date, "\n";
以上就是【perl获取日期与时间的实例代码】的全部内容了,欢迎留言评论进行交流!