date()
格式化本地一个时间/日期
string date(string $format[, int $timestamp])
返回按照format给定格式字符串而产生的字符串,如果timestamp没有给出,默认使用当前本地时间即time()
date_default_timezone_set()
设定所有日期时间函数在当前脚本中所使用的默认时区
bool date_default_timezone_set( string $timezone)
如果参数timezone无效返回false否则返回true
中国时区设定:PRC
<?php
date_default_timezone_set('PRC');
echo date('Y-m-d H:i:s');
?>
date_default_timezone_get()
取得当前脚本默认时区
getdate()
取得一个日期时间信息
array getdate([int $timestamp])
根据timestamp返回一个日期时间的数组信息,如果timestamp没有提供则使用本地当前时间time()
<?php
print_R(getdate());
?>
输出:
Array ( [seconds] => 9 [minutes] => 59 [hours] => 3 [mday] => 28 [wday] => 3 [mon] => 11 [year] => 2012 [yday] => 332 [weekday] => Wednesday [month] => November [0] => 1354075149 )
返回当前时间戳
mktime()
取得一个日期的时间戳
int mktime(int $hour[, int $minute[, int $second[, int $month[, int $day[, int $year]]]])
根据给出的时间返回对应时间戳,出错时返回false
参数可以自右想左省略,省略的参数用本地的时间代替。
strtotime()
将任何格式的英文格式日期转换为unix时间戳
int strtotime(string $time[, int $now])
本函数预期接受一个包含美国英语日期格式的字符串并尝试将其解析为 Unix 时间戳(自 January 1 1970 00:00:00 GMT 起的秒数),其值相对于 now 参数给出的时间,如果没有提供此参数则用系统当前时间。
<?php
echo strtotime('now');//1354004823
echo strtotime('+1 second');//1354004824
?>