时间是实际应用中不可或缺的部分。
时区
时区设置影响到与时间相关的函数。比如 date() 等。
# 设置默认时区 date_default_timezone_set('Asia/Shanghai'); # 查询当前默认时区 $time_zone = date_default_timezone_get();
PHP中可用的时区列表
常用的时间函数
print date( "Y-m-d H:i:s"); # 输出 2009-02-13 13:14:25 print gmdate( "Y-m-d H:i:s"); # 输出标准时间 # 获取时间信息 list($seconds, $minutes, $hours, $mday, $wday, $mon, $year, $yday, $weekday, $month, $timestamp) = getdate(); # $mday = [0..31], $wday = [0..6], $yday = [0..365] # 方便的 strtotime echo strtotime("now"), "\n"; echo strtotime("10 September 2000"), "\n"; echo strtotime("+1 day"), "\n"; echo strtotime("+1 week"), "\n"; echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n"; echo strtotime("next Thursday"), "\n"; echo strtotime("last Monday"), "\n";