📄 function.date.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</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.date-timezone-set.html">date_timezone_set</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.getdate.html">getdate</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.date" class="refentry"> <div class="refnamediv"> <h1 class="refname">date</h1> <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">date</span> — <span class="dc-title">Format a local time/date</span></p> </div> <div class="refsect1 description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">string</span> <span class="methodname"><b><b>date</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 string formatted according to the given format string using the given integer <i><tt class="parameter">timestamp</tt></i> or the current 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> </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"> The format of the outputted date <a href="language.types.string.html" class="type string">string</a>. See the formatting options below. </p> <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> <th colspan="1">Example returned values</th> </tr> </thead> <tbody valign="middle" class="tbody"> <tr valign="middle"> <td colspan="1" rowspan="1" align="center"><em class="emphasis">Day</em></td> <td colspan="1" rowspan="1" align="left">---</td> <td colspan="1" rowspan="1" align="left">---</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, 2 digits with leading zeros</td> <td colspan="1" rowspan="1" align="left"><i>01</i> to <i>31</i></td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><i>D</i></td> <td colspan="1" rowspan="1" align="left">A textual representation of a day, three letters</td> <td colspan="1" rowspan="1" align="left"><i>Mon</i> through <i>Sun</i></td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><i>j</i></td> <td colspan="1" rowspan="1" align="left">Day of the month without leading zeros</td> <td colspan="1" rowspan="1" align="left"><i>1</i> to <i>31</i></td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><i>l</i> (lowercase 'L')</td> <td colspan="1" rowspan="1" align="left">A full textual representation of the day of the week</td> <td colspan="1" rowspan="1" align="left"><i>Sunday</i> through <i>Saturday</i></td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><i>N</i></td> <td colspan="1" rowspan="1" align="left">ISO-8601 numeric representation of the day of the week (added in PHP 5.1.0)</td> <td colspan="1" rowspan="1" align="left"><i>1</i> (for Monday) through <i>7</i> (for Sunday)</td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><i>S</i></td> <td colspan="1" rowspan="1" align="left">English ordinal suffix for the day of the month, 2 characters</td> <td colspan="1" rowspan="1" align="left"> <i>st</i>, <i>nd</i>, <i>rd</i> or <i>th</i>. Works well with <i>j</i> </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><i>w</i></td> <td colspan="1" rowspan="1" align="left">Numeric representation of the day of the week</td> <td colspan="1" rowspan="1" align="left"><i>0</i> (for Sunday) through <i>6</i> (for Saturday)</td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><i>z</i></td> <td colspan="1" rowspan="1" align="left">The day of the year (starting from 0)</td> <td colspan="1" rowspan="1" align="left"><i>0</i> through <i>365</i></td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="center"><em class="emphasis">Week</em></td> <td colspan="1" rowspan="1" align="left">---</td> <td colspan="1" rowspan="1" align="left">---</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 (added in PHP 4.1.0)</td> <td colspan="1" rowspan="1" align="left">Example: <i>42</i> (the 42nd week in the year)</td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="center"><em class="emphasis">Month</em></td> <td colspan="1" rowspan="1" align="left">---</td> <td colspan="1" rowspan="1" align="left">---</td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><i>F</i></td> <td colspan="1" rowspan="1" align="left">A full textual representation of a month, such as January or March</td> <td colspan="1" rowspan="1" align="left"><i>January</i> through <i>December</i></td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><i>m</i></td> <td colspan="1" rowspan="1" align="left">Numeric representation of a month, with leading zeros</td> <td colspan="1" rowspan="1" align="left"><i>01</i> through <i>12</i></td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><i>M</i></td> <td colspan="1" rowspan="1" align="left">A short textual representation of a month, three letters</td> <td colspan="1" rowspan="1" align="left"><i>Jan</i> through <i>Dec</i></td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><i>n</i></td> <td colspan="1" rowspan="1" align="left">Numeric representation of a month, without leading zeros</td> <td colspan="1" rowspan="1" align="left"><i>1</i> through <i>12</i></td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><i>t</i></td> <td colspan="1" rowspan="1" align="left">Number of days in the given month</td> <td colspan="1" rowspan="1" align="left"><i>28</i> through <i>31</i></td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="center"><em class="emphasis">Year</em></td> <td colspan="1" rowspan="1" align="left">---</td> <td colspan="1" rowspan="1" align="left">---</td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><i>L</i></td> <td colspan="1" rowspan="1" align="left">Whether it's a leap year</td> <td colspan="1" rowspan="1" align="left"><i>1</i> if it is a leap year, <i>0</i> otherwise.</td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><i>o</i></td> <td colspan="1" rowspan="1" align="left">ISO-8601 year number. This has the same value as <i>Y</i>, except that if the ISO week number (<i>W</i>) belongs to the previous or next year, that year
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -