Date/Time处理函数总结 [To Do]

23 篇文章 0 订阅
19 篇文章 0 订阅
几种我所用到的用来处理日期,时间的函数总结。

[u][b]Perl[/b][/u]

1. 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.


2. 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 的命令的字符格式是一样的), 参见

[url]http://www.php-oa.com/2010/08/21/perl-strftime.html[/url]

% 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等)

3. 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

4. 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([$gmt]);

Now
($hour,$min,$sec) = Now([$gmt]);

Delta_Days
$Dd = Delta_Days($year1,$month1,$day1,
$year2,$month2,$day2);

5. Date::Parse

[url]http://search.cpan.org/~gbarr/TimeDate-2.30/lib/Date/Parse.pm[/url]
Used to parse date string into time values.

str2time(DATE [, ZONE])

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 [, ZONE])

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.

[u][b]Java[/b][/u]
参考:[url]http://tianlovv.iteye.com/blog/402116[/url]

[u][b]JavaScript[/b][/u]

创建一个日期对象:

var objDate=new Date([arguments list]);

参数形式有以下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的整数

参考:
[url]http://www.cnblogs.com/east-liujie/archive/2006/10/21/535784.html[/url]

[u][b]Sybase[/b][/u]
http://wang-zhi-peng2007.iteye.com/blog/1199091
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值