Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1511404
  • 博文数量: 289
  • 博客积分: 11086
  • 博客等级: 上将
  • 技术积分: 3291
  • 用 户 组: 普通用户
  • 注册时间: 2006-06-22 17:06
个人简介

徐小玉的博客。

文章分类

全部博文(289)

文章存档

2023年(6)

2022年(1)

2021年(2)

2020年(9)

2019年(9)

2018年(6)

2017年(10)

2016年(10)

2014年(3)

2013年(4)

2011年(12)

2010年(16)

2009年(14)

2008年(119)

2007年(48)

2006年(20)

我的朋友

分类: PERL

2019-10-22 11:15:20


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

阅读(1586) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~