📄 function.idate.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Format a local time/date as integer</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.gmstrftime.html">gmstrftime</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.localtime.html">localtime</a></div> <div class="up"><a href="ref.datetime.html">Date/Time Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="function.idate" class="refentry"> <div class="refnamediv"> <h1 class="refname">idate</h1> <p class="verinfo">(PHP 5)</p><p class="refpurpose"><span class="refname">idate</span> — <span class="dc-title">Format a local time/date as integer</span></p> </div> <div class="refsect1 description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">int</span> <span class="methodname"><b><b>idate</b></b></span> ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$format</tt></span> [, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$timestamp</tt></span> ] )</div> <p class="para rdfs-comment"> Returns a number formatted according to the given format string using the given integer <i><tt class="parameter">timestamp</tt></i> or the current local time if no timestamp is given. In other words, <i><tt class="parameter">timestamp</tt></i> is optional and defaults to the value of <a href="function.time.html" class="function">time()</a>. </p> <p class="para"> Unlike the function <a href="function.date.html" class="function">date()</a>, <b>idate()</b> accepts just one char in the <i><tt class="parameter">format</tt></i> parameter. </p> </div> <div class="refsect1 parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><i><tt class="parameter">format</tt></i></span> <dd> <p class="para"> <table border="5"> <caption><b>The following characters are recognized in the <i><tt class="parameter">format</tt></i> parameter string</b></caption> <colgroup> <thead valign="middle"> <tr valign="middle"> <th colspan="1"><i><tt class="parameter">format</tt></i> character</th> <th colspan="1">Description</th> </tr> </thead> <tbody valign="middle" class="tbody"> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><i>B</i></td> <td colspan="1" rowspan="1" align="left">Swatch Beat/Internet Time</td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><i>d</i></td> <td colspan="1" rowspan="1" align="left">Day of the month</td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><i>h</i></td> <td colspan="1" rowspan="1" align="left">Hour (12 hour format)</td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><i>H</i></td> <td colspan="1" rowspan="1" align="left">Hour (24 hour format)</td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><i>i</i></td> <td colspan="1" rowspan="1" align="left">Minutes</td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><i>I</i> (uppercase i)</td> <td colspan="1" rowspan="1" align="left">returns <i>1</i> if DST is activated, <i>0</i> otherwise</td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><i>L</i> (uppercase l)</td> <td colspan="1" rowspan="1" align="left">returns <i>1</i> for leap year, <i>0</i> otherwise</td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><i>m</i></td> <td colspan="1" rowspan="1" align="left">Month number</td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><i>s</i></td> <td colspan="1" rowspan="1" align="left">Seconds</td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><i>t</i></td> <td colspan="1" rowspan="1" align="left">Days in current month</td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><i>U</i></td> <td colspan="1" rowspan="1" align="left">Seconds since the Unix Epoch - January 1 1970 00:00:00 UTC - this is the same as <a href="function.time.html" class="function">time()</a></td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><i>w</i></td> <td colspan="1" rowspan="1" align="left">Day of the week (<i>0</i> on Sunday)</td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><i>W</i></td> <td colspan="1" rowspan="1" align="left">ISO-8601 week number of year, weeks starting on Monday</td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><i>y</i></td> <td colspan="1" rowspan="1" align="left">Year (1 or 2 digits - check note below)</td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><i>Y</i></td> <td colspan="1" rowspan="1" align="left">Year (4 digits)</td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><i>z</i></td> <td colspan="1" rowspan="1" align="left">Day of the year</td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><i>Z</i></td> <td colspan="1" rowspan="1" align="left">Timezone offset in seconds</td> </tr> </tbody> </colgroup> </table> </p> </dd> </dt> <dt><span class="term"><i><tt class="parameter">timestamp</tt></i></span><dd><p class="para">The optional <i><tt class="parameter">timestamp</tt></i> parameter is an <a href="language.types.integer.html" class="type integer">integer</a> Unix timestamp that defaults to the currentlocal time if a <i><tt class="parameter">timestamp</tt></i> is not given. In other words, it defaults to the value of <a href="function.time.html" class="function">time()</a>. </p></dd></dt> </dl> </p> </div> <div class="refsect1 returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns an <a href="language.types.integer.html" class="type integer">integer</a>. </p> <p class="para"> As <b>idate()</b> always returns an <a href="language.types.integer.html" class="type integer">integer</a> and as they can't start with a "0", <b>idate()</b> may return fewer digits than you would expect. See the example below. </p> </div> <div class="refsect1 errors"> <h3 class="title">Errors/Exceptions</h3> <p class="para">Every call to a date/time function will generate a <b><tt>E_NOTICE</tt></b> if the time zone is not valid, and/or a <b><tt>E_STRICT</tt></b> messageif using the system settings or the <var class="varname">TZ</var> environmentvariable. See also <a href="function.date-default-timezone-set.html" class="function">date_default_timezone_set()</a></p> </div> <div class="refsect1 changelog"> <h3 class="title">ChangeLog</h3> <p class="para"> <table class="informaltable"> <colgroup> <thead valign="middle"> <tr valign="middle"> <th colspan="1">Version</th> <th colspan="1">Description</th> </tr> </thead> <tbody valign="middle" class="tbody"> <tr valign="middle"><td colspan="1" rowspan="1" align="left">5.1.0</td><td colspan="1" rowspan="1" align="left"><p class="para">Now issues the <b><tt>E_STRICT</tt></b> and <b><tt>E_NOTICE</tt></b> time zone errors.</p></td></tr> </tbody> </colgroup> </table> </p> </div> <div class="refsect1 examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example"> <p><b>Example #1 <b>idate()</b> example</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br />$timestamp </span><span style="color: #007700">= </span><span style="color: #0000BB">strtotime</span><span style="color: #007700">(</span><span style="color: #DD0000">'1st January 2004'</span><span style="color: #007700">); </span><span style="color: #FF8000">//1072915200<br /><br />// this prints the year in a two digit format<br />// however, as this would start with a "0", it<br />// only prints "4"<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">idate</span><span style="color: #007700">(</span><span style="color: #DD0000">'y'</span><span style="color: #007700">, </span><span style="color: #0000BB">$timestamp</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> </p> </div> <div class="refsect1 seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"><a href="function.date.html" class="function" rel="rdfs-seeAlso">date()</a></li> <li class="member"><a href="function.time.html" class="function" rel="rdfs-seeAlso">time()</a></li> </ul> </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.gmstrftime.html">gmstrftime</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.localtime.html">localtime</a></div> <div class="up"><a href="ref.datetime.html">Date/Time Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -