XXII. Date/Time 日期/时间函数
简介
可以用这些函数得到 PHP 所运行的服务器的日期和时间。可以用这些函数将日期和时间以很多不同方式格式化输出。
注意: 请留意这些函数依赖于服务器的地区设置。确认在使用这些函数时考虑到了夏令时的设置(例如使用 $date = strtotime('+7 days', $date) 而不是 $date += 7*24*60*60)和闰年。
注意: 该部份所提及的时区可参考附录I, 所支持时区列表。
需求
要编译本扩展模块无需外部库文件。
安装
本扩展模块作为 PHP 内核的一部分,无需安装即可使用。
运行时配置
本扩展模块在 php.ini 中未定义任何配置选项。
运行时配置
这些函数的行为受 php.ini 的影响。
表37.日期/时间配置选项
| 名称 | 默认值 | 可修改范围 | 更新记录 |
|---|---|---|---|
| date.default_latitude | "31.7667" | PHP_INI_ALL | 自 PHP 5.0.0 起可用 |
| date.default_longitude | "35.2333" | PHP_INI_ALL | 自 PHP 5.0.0 起可用 |
| date.sunrise_zenith | "90.83" | PHP_INI_ALL | 自 PHP 5.0.0 起可用 |
| date.sunset_zenith | "90.83" | PHP_INI_ALL | 自 PHP 5.0.0 起可用 |
| date.timezone | "" | PHP_INI_ALL | 自 PHP 5.0.0 起可用 |
有关 PHP_INI_* 常量进一步的细节与定义参见附录H, php.ini 配置选项。
以下是配置选项的简要解释。
注意: 前四个配置选项目前仅用于 date_sunrise() 和 date_sunset()。
资源类型
本扩展模块未定义任何资源类型。
预定义常量
自 PHP 5.1.1 起定义有以下常量来提供标准日期表达方法,可以用于日期格式函数(例如 date())。
- DATE_ATOM(string)
- 原子钟格式(如:2005-08-15T15:52:01+00:00)
- DATE_COOKIE(string)
- HTTP Cookies 格式(如:Mon, 15 Aug 2005 15:52:01 UTC)
- DATE_ISO8601(string)
- ISO-8601(如:2005-08-15T15:52:01+0000)
- DATE_RFC822(string)
- RFC 822(如:Mon, 15 Aug 2005 15:52:01 UTC)
- DATE_RFC850(string)
- RFC 850(如:Monday, 15-Aug-05 15:52:01 UTC)
- DATE_RFC1036(string)
- RFC 1036(如:Monday, 15-Aug-05 15:52:01 UTC)
- DATE_RFC1123(string)
- RFC 1123(如:Mon, 15 Aug 2005 15:52:01 UTC)
- DATE_RFC2822(string)
- RFC 2822(如:Mon, 15 Aug 2005 15:52:01 +0000)
- DATE_RSS(string)
- RSS(如:Mon, 15 Aug 2005 15:52:01 UTC)
- DATE_W3C(string)
- World Wide Web Consortium(如:2005-08-15T15:52:01+00:00)
目录
- checkdate 验证一个格里高里日期
- date_create Returns new DateTime object
- date_date_set Sets the date
- date_default_timezone_get 取得一个脚本中所有日期时间函数所使用的默认时区
- date_default_timezone_set 设定用于一个脚本中所有日期时间函数的默认时区
- date_format Returns date formatted according to given format
- date_isodate_set Sets the ISO date
- date_modify Alters the timestamp
- date_offset_get Returns the daylight saving time offset
- date_parse Returns associative array with detailed info about given date
- date_sun_info Returns an array with information about sunset/sunrise and twilight begin/end
- date_sunrise 返回给定的日期与地点的日出时间
- date_sunset 返回给定的日期与地点的日落时间
- date_time_set Sets the time
- date_timezone_get Return time zone relative to given DateTime
- date_timezone_set Sets the time zone for the DateTime object
- date 格式化一个本地时间/日期
- getdate 取得日期/时间信息
- gettimeofday 取得当前时间
- gmdate 格式化一个 GMT/UTC 日期/时间
- gmmktime 取得 GMT 日期的 UNIX 时间戳
- gmstrftime 根据区域设置格式化 GMT/UTC 时间/日期
- idate 将本地时间日期格式化为整数
- localtime 取得本地时间
- microtime 返回当前 Unix 时间戳和微秒数
- mktime 取得一个日期的 Unix 时间戳
- strftime 根据区域设置格式化本地时间/日期
- strptime 解析由 strftime() 生成的日期/时间
- strtotime 将任何英文文本的日期时间描述解析为 Unix 时间戳
- time 返回当前的 Unix 时间戳
- timezone_abbreviations_list Returns associative array containing dst, offset and the timezone name
- timezone_identifiers_list Returns numerically index array with all timezone identifiers
- timezone_name_from_abbr Returns the timezone name from abbrevation
- timezone_name_get Returns the name of the timezone
- timezone_offset_get Returns the timezone offset from GMT
- timezone_open Returns new DateTimeZone object
- timezone_transitions_get Returns all transitions for the timezone
add a note
User Contributed NotesDate/Time 日期/时间函数
There are no user contributed notes for this page.

cyrus_unbind