Date/Time函数总结

/*************by Jiangong SUN*********************/

 

//set default timezone
date_default_timezone_set('Europe/Paris');
echo date_default_timezone_get().'<br />';

 

//day

echo date('d-D-j-l-N-S-w-z').'<br />';

 

//week
echo date('W').'<br />';

 

//month
echo date('F-m-M-n-t').'<br />';

 

//year
echo date('L-o-Y-y').'<br />';

 

//time
echo date('a-A-B-g-G-h-H-i-s-u').'<br />';

 

//timezone
echo date('e-I-O-P-T-Z').'<br />';

 

//full date/time
echo date('c-r-U').'<br />';

echo date('2').'<br />';  //显示2
echo date('monday').'<br />'; //显示m2010901pm10
echo date('/m/o/n/d/a/y').'<br />'; //显示monday

//date -- 格式化一个本地时间/日期
//gmdate -- 格式化一个 GMT/UTC 日期/时间,返回的是格林威治标准时(GMT-Greenwich Mean Time)。

 

UTC (Coordinated Universal Time)世界协调时间

 

echo date('c').'<br />';
echo gmdate('c').'<br />';

//idate -- 将本地时间/日期化为整数
echo idate('Y').'<br />'; //2010

 

//getdate --获得时间/日期信息
print_r(getdate()).'<br />'; //返回的是一个数组

 

结果如:Array ( [seconds] => 47 [minutes] => 44 [hours] => 23 [mday] => 1 [wday] => 3 [mon] => 9 [year] => 2010 [yday] => 243 [weekday] => Wednesday [month] => September [0] => 1283377487 )
ps: 0 --    自从 Unix 纪元开始至今的秒数,和 time() 的返回值以及用于 date() 的值类似。     系统相关,典型值为从 -2147483648 到 2147483647。

 

 

UTC/GMT解释:

 

UTC: Coordinated Universal Time

 

UTC uses a 24-hour system of time notation. "1:00 a.m." in UTC is expressed as 0100, pronounced "zero one hundred." Fifteen minutes after 0100 is expressed as 0115; thirty-eight minutes after 0100 is 0138 (usually pronounced "zero one thirty-eight"). The time one minute after 0159 is 0200. The time one minute after 1259 is 1300 (pronounced "thirteen hundred"). This continues until 2359. One minute later is 0000 ("zero hundred"), and the start of a new UTC day.

 

UTC使用24小时制, 1am 用 0100表示, 23点59分用2359表示, 0点/24点用0000。

 

北京是UTC+800

 

GMT: Greenwich Mean Time

 

UTC就是GMT的另一种表示。

 

 

 


//time返回当前时间的Unix时间戳
echo time().'<br />';


//microtime:返回unix时间戳,从1970年1月1日到现在的秒数和微秒数
//如果调用时不带可选参数,本函数以 "msec sec" 的格式返回一个字符串,其中 sec 是自 Unix 纪元(0:00:00 January 1, 1970 GMT)起到现在的秒数,msec 是微秒部分。字符串的两部分都是以秒为单位返回的。
echo microtime().'<br />'; //0.05199400 1283465022

 

//mktime返回一个时间的unix时间戳
echo date('c', mktime(1,2,3,4,5,2006)).'<br />'; //小时,分,秒,月,天,年;显示:2006-04-05T01:02:03+02:00
echo mktime(1,2,3,9,2,2010).'<br />';

 

//gmmktime返回GMT的unix时间戳
echo gmmktime().'<br />';

 

//strftime按照本地区域设置格式化时间/日期
echo strftime("%A").'<br />'; //Friday

 

//gmstrftime按照GMT时间格式化时间/日期
echo gmstrftime("%A").'<br />'; //Thursday

 

//strptime在windows系统中不支持此函数。它用来解析strftime生成的时间/日期。
//setlocale(LC_ALL, 'fr_FR');
//$format = '%d/%m/%Y %H:%M:%S';
//$strf = strftime($format);
//echo "$strf/n";
//print_r(strptime($strf, $format));
//setlocale设置地区信息(地域信息)

 

/* Set locale to Dutch */
setlocale(LC_ALL, 'nld_nld');
/* Output: vrijdag 22 december 1978 */
echo strftime("%A %d %B %Y", mktime(0, 0, 0, 12, 22, 1978)).'<br />';
/* try different possible locale names for german as of PHP 4.3.0 */
$loc_de = setlocale(LC_ALL, 'de_DE@euro', 'de_DE', 'deu_deu');
echo "Preferred locale for german on this system is '$loc_de'".'<br />';

echo setlocale(LC_ALL,"En_Us").'<br />';
echo setlocale(LC_ALL,NULL).'<br />';


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值