<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >Date/Time 日期/时间函数</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="PHP 手册" HREF="index.html"><LINK REL="UP" TITLE="函数参考" HREF="funcref.html"><LINK REL="PREVIOUS" TITLE="cyrus_unbind" HREF="function.cyrus-unbind.html"><LINK REL="NEXT" TITLE="checkdate" HREF="function.checkdate.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"></HEAD ><BODY CLASS="reference" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP 手册</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.cyrus-unbind.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.checkdate.html" ACCESSKEY="N" >下一页</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="reference" ><A NAME="ref.datetime" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" >XXII. Date/Time 日期/时间函数</H1 ><DIV CLASS="PARTINTRO" ><A NAME="AEN27841" ></A ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="datetime.intro" >简介</A ></H1 ><P > 可以用这些函数得到 PHP 所运行的服务器的日期和时间。可以用这些函数将日期和时间以很多不同方式格式化输出。 </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >注意: </B > 请留意这些函数依赖于服务器的地区设置。确认在使用这些函数时考虑到了夏令时的设置(例如使用 <TT CLASS="literal" >$date = strtotime('+7 days', $date)</TT > 而不是 <TT CLASS="literal" >$date += 7*24*60*60</TT >)和闰年。 </P ></BLOCKQUOTE ></DIV ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >注意: </B > 该部份所提及的时区可参考<A HREF="timezones.html" >附录 I</A >。 </P ></BLOCKQUOTE ></DIV ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="datetime.required" >需求</A ></H1 ><P >要编译本扩展模块无需外部库文件。</P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="datetime.installation" >安装</A ></H1 ><P >本扩展模块作为 PHP 内核的一部分,无需安装即可使用。</P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="datetime.runtime" >运行时配置</A ></H1 ><P >本扩展模块在 <TT CLASS="filename" >php.ini</TT > 中未定义任何配置选项。</P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="datetime.configuration" >运行时配置</A ></H1 ><P >这些函数的行为受 <TT CLASS="filename" >php.ini</TT > 的影响。</P ><P > <DIV CLASS="table" ><A NAME="AEN27867" ></A ><P ><B >表 1. 日期/时间配置选项</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><COL><COL><COL><COL><THEAD ><TR ><TH >名称</TH ><TH >默认值</TH ><TH >可修改范围</TH ><TH >更新记录</TH ></TR ></THEAD ><TBODY ><TR ><TD >date.default_latitude</TD ><TD >"31.7667"</TD ><TD >PHP_INI_ALL</TD ><TD >自 PHP 5.0.0 起可用</TD ></TR ><TR ><TD >date.default_longitude</TD ><TD >"35.2333"</TD ><TD >PHP_INI_ALL</TD ><TD >自 PHP 5.0.0 起可用</TD ></TR ><TR ><TD >date.sunrise_zenith</TD ><TD >"90.83"</TD ><TD >PHP_INI_ALL</TD ><TD >自 PHP 5.0.0 起可用</TD ></TR ><TR ><TD >date.sunset_zenith</TD ><TD >"90.83"</TD ><TD >PHP_INI_ALL</TD ><TD >自 PHP 5.0.0 起可用</TD ></TR ><TR ><TD >date.timezone</TD ><TD >""</TD ><TD >PHP_INI_ALL</TD ><TD >自 PHP 5.0.0 起可用</TD ></TR ></TBODY ></TABLE ></DIV > 有关 PHP_INI_* 常量进一步的细节与定义参见<A HREF="ini.html" >附录 H</A >。 </P ><P >以下是配置选项的简要解释。</P ><P > <P ></P ><DIV CLASS="variablelist" ><DL ><DT ><A NAME="ini.date.default-latitude" ></A ><CODE CLASS="parameter" >date.default_latitude</CODE > <A HREF="language.types.float.html" ><B CLASS="type" >float</B ></A ></DT ><DD ><P > 默认纬度。 </P ></DD ><DT ><A NAME="ini.date.default-longitude" ></A ><CODE CLASS="parameter" >date.default_longitude</CODE > <A HREF="language.types.float.html" ><B CLASS="type" >float</B ></A ></DT ><DD ><P > 默认经度。 </P ></DD ><DT ><A NAME="ini.date.sunrise-zenith" ></A ><CODE CLASS="parameter" >date.sunrise_zenith</CODE > <A HREF="language.types.float.html" ><B CLASS="type" >float</B ></A ></DT ><DD ><P > 默认日出天顶。 </P ></DD ><DT ><A NAME="ini.date.sunset-zenith" ></A ><CODE CLASS="parameter" >date.sunset_zenith</CODE > <A HREF="language.types.float.html" ><B CLASS="type" >float</B ></A ></DT ><DD ><P > 默认日落天顶。 </P ></DD ><DT ><A NAME="ini.date.timezone" ></A ><CODE CLASS="parameter" >date.timezone</CODE > <A HREF="language.types.string.html" ><B CLASS="type" >string</B ></A ></DT ><DD ><P > 在未设定 <CODE CLASS="varname" >TZ</CODE > 环境变量时用于所有日期/时间函数的默认时区。优先顺序在 <A HREF="function.date-default-timezone-get.html" ><B CLASS="function" >date_default_timezone_get()</B ></A > 页面中有说明。 </P ></DD ></DL ></DIV > </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >注意: </B > 前四个配置选项目前仅用于 <A HREF="function.date-sunrise.html" ><B CLASS="function" >date_sunrise()</B ></A > 和 <A HREF="function.date-sunset.html" ><B CLASS="function" >date_sunset()</B ></A >。 </P ></BLOCKQUOTE ></DIV ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="datetime.resources" >资源类型</A ></H1 ><P >本扩展模块未定义任何资源类型。</P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="datetime.constants" >预定义常量</A ></H1 ><P > 自 PHP 5.1.1 起定义有以下常量来提供标准日期表达方法,可以用于日期格式函数(例如 <A HREF="function.date.html" ><B CLASS="function" >date()</B ></A >)。 </P ><P ></P ><DIV CLASS="variablelist" ><DL ><DT ><TT CLASS="constant" ><B >DATE_ATOM</B ></TT >(<A HREF="language.types.string.html" ><B CLASS="type" >string</B ></A >)</DT ><DD ><P > 原子钟格式(如:2005-08-15T15:52:01+00:00) </P ></DD ><DT ><TT CLASS="constant" ><B >DATE_COOKIE</B ></TT >(<A HREF="language.types.string.html" ><B CLASS="type" >string</B ></A >)</DT ><DD ><P > HTTP Cookies 格式(如:Mon, 15 Aug 2005 15:52:01 UTC) </P ></DD ><DT ><TT CLASS="constant" ><B >DATE_ISO8601</B ></TT >(<A HREF="language.types.string.html" ><B CLASS="type" >string</B ></A >)</DT ><DD ><P > ISO-8601(如:2005-08-15T15:52:01+0000) </P ></DD ><DT ><TT CLASS="constant" ><B >DATE_RFC822</B ></TT >(<A HREF="language.types.string.html" ><B CLASS="type" >string</B ></A >)</DT ><DD ><P > RFC 822(如:Mon, 15 Aug 2005 15:52:01 UTC) </P ></DD ><DT ><TT CLASS="constant" ><B >DATE_RFC850</B ></TT >(<A HREF="language.types.string.html" ><B CLASS="type" >string</B ></A >)</DT ><DD ><P > RFC 850(如:Monday, 15-Aug-05 15:52:01 UTC) </P ></DD ><DT ><TT CLASS="constant" ><B >DATE_RFC1036</B ></TT >(<A HREF="language.types.string.html" ><B CLASS="type" >string</B ></A >)</DT ><DD ><P > RFC 1036(如:Monday, 15-Aug-05 15:52:01 UTC) </P ></DD ><DT ><TT CLASS="constant" ><B >DATE_RFC1123</B ></TT >(<A HREF="language.types.string.html" ><B CLASS="type" >string</B ></A >)</DT ><DD ><P > RFC 1123(如:Mon, 15 Aug 2005 15:52:01 UTC) </P ></DD ><DT ><TT CLASS="constant" ><B >DATE_RFC2822</B ></TT >(<A HREF="language.types.string.html" ><B CLASS="type" >string</B ></A >)</DT ><DD ><P > RFC 2822(如:Mon, 15 Aug 2005 15:52:01 +0000) </P ></DD ><DT ><TT CLASS="constant" ><B >DATE_RSS</B ></TT >(<A HREF="language.types.string.html" ><B CLASS="type" >string</B ></A >)</DT ><DD ><P > RSS(如:Mon, 15 Aug 2005 15:52:01 UTC) </P ></DD ><DT ><TT CLASS="constant" ><B >DATE_W3C</B ></TT >(<A HREF="language.types.string.html" ><B CLASS="type" >string</B ></A >)</DT ><DD ><P > World Wide Web Consortium(如:2005-08-15T15:52:01+00:00) </P ></DD ></DL ></DIV ></DIV ></DIV ><DIV CLASS="TOC" ><DL ><DT ><B >目录</B ></DT ><DT ><A HREF="function.checkdate.html" >checkdate</A > -- 验证一个格里高里日期</DT ><DT ><A HREF="function.date-create.html" >date_create</A > -- Returns new DateTime object</DT ><DT ><A HREF="function.date-date-set.html" >date_date_set</A > -- Sets the date</DT ><DT ><A HREF="function.date-default-timezone-get.html" >date_default_timezone_get</A > -- 取得一个脚本中所有日期时间函数所使用的默认时区</DT ><DT ><A HREF="function.date-default-timezone-set.html" >date_default_timezone_set</A > -- 设定用于一个脚本中所有日期时间函数的默认时区</DT ><DT ><A HREF="function.date-format.html" >date_format</A > -- Returns date formatted according to given format</DT ><DT ><A HREF="function.date-isodate-set.html" >date_isodate_set</A > -- Sets the ISO date</DT ><DT ><A HREF="function.date-modify.html" >date_modify</A > -- Alters the timestamp</DT ><DT ><A HREF="function.date-offset-get.html" >date_offset_get</A > -- Returns the daylight saving time offset</DT ><DT ><A HREF="function.date-parse.html" >date_parse</A > -- Returns associative array with detailed info about given date</DT ><DT ><A HREF="function.date-sun-info.html" >date_sun_info</A > -- Returns an array with information about sunset/sunrise and twilight begin/end</DT ><DT ><A HREF="function.date-sunrise.html" >date_sunrise</A > -- 返回给定的日期与地点的日出时间</DT ><DT ><A HREF="function.date-sunset.html" >date_sunset</A > -- 返回给定的日期与地点的日落时间</DT ><DT ><A HREF="function.date-time-set.html" >date_time_set</A > -- Sets the time</DT ><DT ><A HREF="function.date-timezone-get.html" >date_timezone_get</A > -- Return time zone relative to given DateTime</DT ><DT ><A HREF="function.date-timezone-set.html" >date_timezone_set</A > -- Sets the time zone for the DateTime object</DT ><DT ><A HREF="function.date.html" >date</A > -- 格式化一个本地时间/日期</DT ><DT ><A HREF="function.getdate.html" >getdate</A > -- 取得日期/时间信息</DT ><DT ><A HREF="function.gettimeofday.html" >gettimeofday</A > -- 取得当前时间</DT ><DT ><A HREF="function.gmdate.html" >gmdate</A > -- 格式化一个 GMT/UTC 日期/时间</DT ><DT ><A HREF="function.gmmktime.html" >gmmktime</A > -- 取得 GMT 日期的 UNIX 时间戳</DT ><DT ><A HREF="function.gmstrftime.html" >gmstrftime</A > -- 根据区域设置格式化 GMT/UTC 时间/日期 </DT ><DT ><A HREF="function.idate.html" >idate</A > -- 将本地时间日期格式化为整数</DT ><DT ><A HREF="function.localtime.html" >localtime</A > -- 取得本地时间</DT ><DT ><A HREF="function.microtime.html" >microtime</A > -- 返回当前 Unix 时间戳和微秒数</DT ><DT ><A HREF="function.mktime.html" >mktime</A > -- 取得一个日期的 Unix 时间戳</DT ><DT ><A HREF="function.strftime.html" >strftime</A > -- 根据区域设置格式化本地时间/日期</DT ><DT ><A HREF="function.strptime.html" >strptime</A > -- 解析由 <A HREF="function.strftime.html" ><B CLASS="function" >strftime()</B ></A > 生成的日期/时间</DT ><DT ><A HREF="function.strtotime.html" >strtotime</A > -- 将任何英文文本的日期时间描述解析为 Unix 时间戳</DT ><DT ><A HREF="function.time.html" >time</A > -- 返回当前的 Unix 时间戳</DT ><DT ><A HREF="function.timezone-abbreviations-list.html" >timezone_abbreviations_list</A > -- Returns associative array containing dst, offset and the timezone name</DT ><DT ><A HREF="function.timezone-identifiers-list.html" >timezone_identifiers_list</A > -- Returns numerically index array with all timezone identifiers</DT ><DT ><A HREF="function.timezone-name-from-abbr.html" >timezone_name_from_abbr</A > -- Returns the timezone name from abbrevation</DT ><DT ><A HREF="function.timezone-name-get.html" >timezone_name_get</A > -- Returns the name of the timezone</DT ><DT ><A HREF="function.timezone-offset-get.html" >timezone_offset_get</A > -- Returns the timezone offset from GMT</DT ><DT ><A HREF="function.timezone-open.html" >timezone_open</A > -- Returns new DateTimeZone object</DT ><DT ><A HREF="function.timezone-transitions-get.html" >timezone_transitions_get</A > -- Returns all transitions for the timezone</DT ></DL ></DIV ></DIV ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.cyrus-unbind.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >起始页</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.checkdate.html" ACCESSKEY="N" >下一页</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >cyrus_unbind</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="funcref.html" ACCESSKEY="U" >上一级</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >checkdate</TD ></TR ></TABLE ></DIV ></BODY ></HTML >