| 时间函数 | |||||
| 函数名 | 描述 | 实例 | 输入 | 输出 | 操作 |
| time() | 返回当前的 Unix 时间戳 | time(); | int time ( void ) | 返回自从 Unix 纪元(格林威治时间 1970 年 1 月 1 日 00:00:00)到当前时间的秒数 | |
| mktime() | 取得一个日期的 Unix 时间戳 | mktime(0, 0, 0, 4, 25, 2012); | int mktime ([ int $hour [, int $minute [, int $second [, int $month [, int $day [, int $year [, int $is_dst ]]]]]]] ) | ||
| date() | 格式化一个本地时间/日期 | date('Y年m月d日 H:i:s'); | string date ( string $format [, int $timestamp ] ) | 2012年04月25日 20:45:54 | |
| checkdate() | 验证一个格里高里日期 |
if(checkdate(6,31,2012)){ echo '成立'; }else{ echo '不成立'; } | bool checkdate ( int $month , int $day , int $year ) | 如果给出的日期有效则返回 TRUE,否则返回 FALSE | |
| date_default_timezone_set() | 设定用于一个脚本中所有日期时间函数的默认时区 | date_default_timezone_set('PRC'); | bool date_default_timezone_set ( string $timezone_identifier ) | ||
| getdate() | 取得日期/时间信息 |
$t=getdate(); var_dump($t); | array getdate ([ int $timestamp ] ) | 返回一个根据 timestamp 得出的包含有日期信息的结合数组。如果没有给出时间戳则认为是当前本地时间 | |
| strtotime() | 将任何英文文本的日期时间描述解析为 Unix 时间戳 |
echo strtotime("now"); echo strtotime("10 September 2000"); echo strtotime("+1 day"); echo strtotime("+1 week"); echo strtotime("+1 week 2 days 4 hours 2 seconds"); echo strtotime("next Thursday"); echo strtotime("last Monday"); | int strtotime ( string $time [, int $now ] ) | ||
| microtime() | 返回当前 Unix 时间戳和微秒数 |
$start=microtime(true); sleep(3); $stop=microtime(true); echo $stop-$start; | mixed microtime ([ bool $get_as_float ] ) | ||
PHP函数(四) 时间函数
本文介绍了多个用于处理时间和日期的函数,包括获取Unix时间戳、格式化日期、验证日期有效性等功能,并提供了具体用例。

被折叠的 条评论
为什么被折叠?



