Date/Time处理函数总结 [To Do]
几种我所用到的用来处理日期,时间的函数总结。
Perl
- localtime
# 0 1 2 3 4 5 6 7 8
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
localtime(time);
If parameter is not provides, it will use current time. Note the $year returned contains the number of years since 1900, to get a 4-digit year you need:
$year += 1900;
And the $mon starts from 0 to 11.
- strftime
use POSIX qw(strftime);
$now_string = strftime "%a %b %e %H:%M:%S %Y", localtime;
# or for GMT formatted appropriately for your locale:
$now_string = strftime "%a %b %e %H:%M:%S %Y", gmtime;
Strftime 时间域 ( 这个和 date 的命令的字符格式是一样的), 参见
http://www.php-oa.com/2010/08/21/perl-strftime.html
% H 小时(00..23) % I 小时(01..12) % k 小时(0..23) % l 小时(1..12) % M 分(00..59) % p 显示出AM或PM % r 时间(hh:mm:ss AM或PM),12小时 % s 从1970年1月1日00:00:00到目前经历的秒数 % S 秒(00..59) % T 时间(24小时制)(hh:mm:ss) % X 显示时间的格式(%H:%M:%S) % Z 时区 日期域 % a 星期几的简称( Sun..Sat) % A 星期几的全称( Sunday..Saturday) % b 月的简称(Jan..Dec) % B 月的全称(January..December) % c 日期和时间( Mon Nov 8 14:12:46 CST 1999) % d 一个月的第几天(01..31) % D 日期(mm/dd/yy) % h 和%b选项相同 % j 一年的第几天(001..366) % m 月(01..12) % w 一个星期的第几天(0代表星期天) % W 一年的第几个星期(00..53,星期一为第一天) % x 显示日期的格式(mm/dd/yy) % y 年的最后两个数字( 1999则是99) % Y 年(例如:1970,1996等)
- time
Returns the number of non-leap seconds since whatever time the system considers to be the epoch, suitable for feeding to gmtime and localtime. On most systems the epoch is 00:00:00 UTC, January 1, 1970
- Date::Calc
Quite useful. Some methods I frequently use:
Add_Delta_Days ($year,$month,$day) = Add_Delta_Days($year,$month,$day, $Dd);
Today ($year,$month,$day) = Today();
Now ($hour,$min,$sec) = Now();
Delta_Days $Dd = Delta_Days($year1,$month1,$day1, $year2,$month2,$day2);
- Date::Parse
http://search.cpan.org/~gbarr/TimeDate-2.30/lib/Date/Parse.pm Used to parse date string into time values.
str2time(DATE )
str2time parses DATE and returns a unix time value, or undef upon failure. ZONE, if given, specifies the timezone to assume when parsing if the date string does not specify a timezone.
strptime(DATE )
strptime takes the same arguments as str2time but returns an array of values ($ss,$mm,$hh,$day,$month,$year,$zone). Elements are only defined if they could be extracted from the date string. The $zone element is the timezone offset in seconds from GMT. An empty array is returned upon failure.
Java 参考:http://tianlovv.iteye.com/blog/402116
JavaScript
创建一个日期对象:
var objDate=new Date();
参数形式有以下5种:
new Date("month dd,yyyy hh:mm:ss"); new Date("month dd,yyyy"); new Date(yyyy,mth,dd,hh,mm,ss); new Date(yyyy,mth,dd); new Date(ms);
需要注意最后一种形式,参数表示的是需要创建的时间和GMT时间1970年1月1日之间相差的毫秒数。各种函数的含义如下:
month:用英文表示月份名称,从January到December
mth:用整数表示月份,从0到11
dd:表示一个月中的第几天,从1到31
yyyy:四位数表示的年份
hh:小时数,从0(午夜)到23(晚11点)
mm:分钟数,从0到59的整数
ss:秒数,从0到59的整数
ms:毫秒数,为大于等于0的整数
参考: http://www.cnblogs.com/east-liujie/archive/2006/10/21/535784.html
Sybase http://wang-zhi-peng2007.iteye.com/blog/1199091