Time
PHP 日期与时间函数
格式化、解析、时区、时间戳互转。跨月跨年的日期计算别用 86400 硬乘。
| 函数 | 说明 | 返回 |
|---|---|---|
| cal_days_in_month() | 返回某年某月有多少天。 | int |
| checkdate() | 检查一个日期是否真实存在,会考虑闰年。 | bool |
| date() | 把时间戳格式化成可读的日期时间字符串。 | string |
| date_default_timezone_set() | 设置脚本的默认时区。不设置时 PHP 会用 UTC 并给出警告。 | bool |
| gmdate() | 按 UTC 格式化时间,不受默认时区影响。 | string |
| microtime() | 返回当前时间的微秒级表示。 | string|float |
| mktime() | 用具体的年月日时分秒构造时间戳。 | int|false |
| strtotime() | 把日期字符串解析成时间戳,支持 +1 day、next Monday 这类相对表达。 | int|false |
| time() | 返回当前 Unix 时间戳,单位秒。 | int |