localtime EXPR
localtime
引用方法:
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
$sec,$min,$hour : seconds, minutes, and hours of the specified time.
$mday : the day of the month
$mon : the month in the range 0..11
$year : contains the number of years since 1900.
To get a 4-digit year write : $year += 1900;
To get the last two digits of the year : $year = sprintf("%02d", $year % 100);
$wday : the day of the week, with 0 indicating Sunday and 3 indicating Wednesday
$yday : the day of the year, in the range 0..364 (or 0..365 in leap years.)
$isdst : true if the specified time occurs during Daylight Saving Time, false otherwise.
一个栗子:
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
my @aweek = qw(Sunday Monday Tuesday Wenday Thursday Friday Saturday);
my @aDayTS= qw(Not-Daytime-saving Daytimesaving);
print "今天是 ", $year +1900," 年", $mon +1," 月 $mday 号. 目前是$aDayTS[$isdst]。 \n", ;
print "Today is $aweek[$wday], is the ", $yday, "th days of this year.\n";
# to obtain the month and day:
my @abbr = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
print "Today is : $abbr[$mon] $mday";
print "\n";
【output】
今天是 2019 年10 月 22 号. 目前是Not-Daytime-saving。
Today is Tuesday, is the 294th days of this year.
Today is : Oct 22
#########
Note: If EXPR is omitted, localtime uses the current time (as returned by time).
尤其注意:
在标量上下文中,localtime返回的的是ctime(3)的值(In scalar context, localtime returns the ctime(3) value):
一个栗子:
print scalar localtime;
print "\n";
[output]:
Tue Oct 22 11:07:08 2019
阅读(1665) | 评论(0) | 转发(0) |