Perl之Time::Local

use Time::Local;

my $now = time(); #取当前的unix时间戳

my ($sec,$min,$hour,$day,$month,$year,$wday,$yday,$isdst) = localtime();

$year = $year + 1900; #注意$year表示它表示从1900年开始的年份,要处理

$month = $month + 1; #注意$month 0开始(代表1月份)

use Date::Parse;

# str2time支持以下格式:

# Sat Mar 14 10:14:05 EDT 2015

# 3/14/2015 10:14:05 -0400

# 14/Mar/15 10:14:05

# 14 Mar 15 10:14:05

my $today = str2time("$month/$day/$year"); #取今天0点的unix时间戳

猜你喜欢

转载自lzqustc.iteye.com/blog/2312862