<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Format a local time/date according to locale settings</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.mktime.html">mktime</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.strptime.html">strptime</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.strftime" class="refentry"> <div class="refnamediv"> <h1 class="refname">strftime</h1> <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">strftime</span> — <span class="dc-title">Format a local time/date according to locale settings</span></p> </div> <div class="refsect1 description" id="refsect1-function.strftime-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">string</span> <span class="methodname"><strong>strftime</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$format</code></span> [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$timestamp</code><span class="initializer"> = time()</span></span> ] )</div> <p class="para rdfs-comment"> Format the time and/or date according to locale settings. Month and weekday names and other language-dependent strings respect the current locale set with <span class="function"><a href="function.setlocale.html" class="function">setlocale()</a></span>. </p> <p class="para"> Not all conversion specifiers may be supported by your C library, in which case they will not be supported by PHP's <span class="function"><strong>strftime()</strong></span>. Additionally, not all platforms support negative timestamps, so your date range may be limited to no earlier than the Unix epoch. This means that %e, %T, %R and, %D (and possibly others) - as well as dates prior to <em>Jan 1, 1970</em> - will not work on Windows, some Linux distributions, and a few other operating systems. For Windows systems, a complete overview of supported conversion specifiers can be found at <a href="http://msdn.microsoft.com/en-us/library/fe06s4ak.aspx" class="link external">» <acronym title="Microsoft Developer Network">MSDN</acronym></a>. </p> </div> <div class="refsect1 parameters" id="refsect1-function.strftime-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">format</code></em></span> <dd> <p class="para"> <table class="doctable table"> <caption><strong>The following characters are recognized in the <em><code class="parameter">format</code></em> parameter string</strong></caption> <thead> <tr> <th><em><code class="parameter">format</code></em></th> <th>Description</th> <th>Example returned values</th> </tr> </thead> <tbody class="tbody"> <tr> <td style="text-align: center;"><em class="emphasis">Day</em></td> <td>---</td> <td>---</td> </tr> <tr> <td><em>%a</em></td> <td>An abbreviated textual representation of the day</td> <td><em>Sun</em> through <em>Sat</em></td> </tr> <tr> <td><em>%A</em></td> <td>A full textual representation of the day</td> <td><em>Sunday</em> through <em>Saturday</em></td> </tr> <tr> <td><em>%d</em></td> <td>Two-digit day of the month (with leading zeros)</td> <td><em>01</em> to <em>31</em></td> </tr> <tr> <td><em>%e</em></td> <td> Day of the month, with a space preceding single digits. Not implemented as described on Windows. See below for more information. </td> <td><em> 1</em> to <em>31</em></td> </tr> <tr> <td><em>%j</em></td> <td>Day of the year, 3 digits with leading zeros</td> <td><em>001</em> to <em>366</em></td> </tr> <tr> <td><em>%u</em></td> <td>ISO-8601 numeric representation of the day of the week</td> <td><em>1</em> (for Monday) though <em>7</em> (for Sunday)</td> </tr> <tr> <td><em>%w</em></td> <td>Numeric representation of the day of the week</td> <td><em>0</em> (for Sunday) through <em>6</em> (for Saturday)</td> </tr> <tr> <td style="text-align: center;"><em class="emphasis">Week</em></td> <td>---</td> <td>---</td> </tr> <tr> <td><em>%U</em></td> <td>Week number of the given year, starting with the first Sunday as the first week</td> <td><em>13</em> (for the 13th full week of the year)</td> </tr> <tr> <td><em>%V</em></td> <td>ISO-8601:1988 week number of the given year, starting with the first week of the year with at least 4 weekdays, with Monday being the start of the week</td> <td><em>01</em> through <em>53</em> (where 53 accounts for an overlapping week)</td> </tr> <tr> <td><em>%W</em></td> <td>A numeric representation of the week of the year, starting with the first Monday as the first week</td> <td><em>46</em> (for the 46th week of the year beginning with a Monday)</td> </tr> <tr> <td style="text-align: center;"><em class="emphasis">Month</em></td> <td>---</td> <td>---</td> </tr> <tr> <td><em>%b</em></td> <td>Abbreviated month name, based on the locale</td> <td><em>Jan</em> through <em>Dec</em></td> </tr> <tr> <td><em>%B</em></td> <td>Full month name, based on the locale</td> <td><em>January</em> through <em>December</em></td> </tr> <tr> <td><em>%h</em></td> <td>Abbreviated month name, based on the locale (an alias of %b)</td> <td><em>Jan</em> through <em>Dec</em></td> </tr> <tr> <td><em>%m</em></td> <td>Two digit representation of the month</td> <td><em>01</em> (for January) through <em>12</em> (for December)</td> </tr> <tr> <td style="text-align: center;"><em class="emphasis">Year</em></td> <td>---</td> <td>---</td> </tr> <tr> <td><em>%C</em></td> <td>Two digit representation of the century (year divided by 100, truncated to an integer)</td> <td><em>19</em> for the 20th Century</td> </tr> <tr> <td><em>%g</em></td> <td>Two digit representation of the year going by ISO-8601:1988 standards (see %V)</td> <td>Example: <em>09</em> for the week of January 6, 2009</td> </tr> <tr> <td><em>%G</em></td> <td>The full four-digit version of %g</td> <td>Example: <em>2008</em> for the week of January 3, 2009</td> </tr> <tr> <td><em>%y</em></td> <td>Two digit representation of the year</td> <td>Example: <em>09</em> for 2009, <em>79</em> for 1979</td> </tr> <tr> <td><em>%Y</em></td> <td>Four digit representation for the year</td> <td>Example: <em>2038</em></td> </tr> <tr> <td style="text-align: center;"><em class="emphasis">Time</em></td> <td>---</td> <td>---</td> </tr> <tr> <td><em>%H</em></td> <td>Two digit representation of the hour in 24-hour format</td> <td><em>00</em> through <em>23</em></td> </tr> <tr> <td><em>%k</em></td> <td>Two digit representation of the hour in 24-hour format, with a space preceding single digits</td> <td><em> 0</em> through <em>23</em></td> </tr> <tr> <td><em>%I</em></td> <td>Two digit representation of the hour in 12-hour format</td> <td><em>01</em> through <em>12</em></td> </tr> <tr> <td><em>%l (lower-case 'L')</em></td> <td>Hour in 12-hour format, with a space preceding single digits</td> <td><em> 1</em> through <em>12</em></td> </tr> <tr> <td><em>%M</em></td> <td>Two digit representation of the minute</td> <td><em>00</em> through <em>59</em></td> </tr> <tr> <td><em>%p</em></td> <td>UPPER-CASE 'AM' or 'PM' based on the given time</td> <td>Example: <em>AM</em> for 00:31, <em>PM</em> for 22:23</td> </tr> <tr> <td><em>%P</em></td> <td>lower-case 'am' or 'pm' based on the given time</td> <td>Example: <em>am</em> for 00:31, <em>pm</em> for 22:23</td> </tr> <tr> <td><em>%r</em></td> <td>Same as "%I:%M:%S %p"</td> <td>Example: <em>09:34:17 PM</em> for 21:34:17</td> </tr> <tr> <td><em>%R</em></td> <td>Same as "%H:%M"</td> <td>Example: <em>00:35</em> for 12:35 AM, <em>16:44</em> for 4:44 PM</td> </tr> <tr> <td><em>%S</em></td> <td>Two digit representation of the second</td> <td><em>00</em> through <em>59</em></td> </tr> <tr> <td><em>%T</em></td> <td>Same as "%H:%M:%S"</td> <td>Example: <em>21:34:17</em> for 09:34:17 PM</td> </tr> <tr> <td><em>%X</em></td> <td>Preferred time representation based on locale, without the date</td> <td>Example: <em>03:59:16</em> or <em>15:59:16</em></td> </tr> <tr> <td><em>%z</em></td> <td>The time zone offset. Not implemented as described on Windows. See below for more information.</td> <td>Example: <em>-0500</em> for US Eastern Time</td> </tr> <tr> <td><em>%Z</em></td> <td>The time zone abbreviation. Not implemented as described on Windows. See below for more information.</td> <td>Example: <em>EST</em> for Eastern Time</td> </tr> <tr> <td style="text-align: center;"><em class="emphasis">Time and Date Stamps</em></td> <td>---</td> <td>---</td> </tr> <tr> <td><em>%c</em></td> <td>Preferred date and time stamp based on locale</td> <td>Example: <em>Tue Feb 5 00:45:10 2009</em> for February 5, 2009 at 12:45:10 AM</td> </tr> <tr> <td><em>%D</em></td> <td>Same as "%m/%d/%y"</td> <td>Example: <em>02/05/09</em> for February 5, 2009</td> </tr> <tr> <td><em>%F</em></td> <td>Same as "%Y-%m-%d" (commonly used in database datestamps)</td> <td>Example: <em>2009-02-05</em> for February 5, 2009</td> </tr> <tr> <td><em>%s</em></td> <td>Unix Epoch Time timestamp (same as the <span class="function"><a href="function.time.html" class="function">time()</a></span> function)</td> <td>Example: <em>305815200</em> for September 10, 1979 08:40:00 AM</td> </tr> <tr> <td><em>%x</em></td> <td>Preferred date representation based on locale, without the time</td> <td>Example: <em>02/05/09</em> for February 5, 2009</td> </tr> <tr> <td style="text-align: center;"><em class="emphasis">Miscellaneous</em></td> <td>---</td> <td>---</td> </tr> <tr> <td><em>%n</em></td> <td>A newline character ("\n")</td> <td>---</td> </tr> <tr> <td><em>%t</em></td> <td>A Tab character ("\t")</td> <td>---</td> </tr> <tr> <td><em>%%</em></td> <td>A literal percentage character ("%")</td> <td>---</td> </tr> </tbody> </table> </p> <p class="para"> Maximum length of this parameter is 1023 characters. </p> <div class="warning"><strong class="warning">Warning</strong> <p class="simpara"> Contrary to ISO-9899:1999, Sun Solaris starts with Sunday as 1. As a result, <em>%u</em> may not function as described in this manual. </p> </div> <div class="warning"><strong class="warning">Warning</strong> <p class="para"> <em class="emphasis">Windows only:</em> </p> <p class="para"> The <em>%e</em> modifier is not supported in the Windows implementation of this function. To achieve this value, the <em>%#d</em> modifier can be used instead. The example below illustrates how to write a cross platform compatible function. </p> <p class="para"> The <em>%z</em> and <em>%Z</em> modifiers both return the time zone name instead of the offset or abbreviation. </p> </div> <div class="warning"><strong class="warning">Warning</strong> <p class="simpara"> <em class="emphasis">Mac OS X only:</em> The <em>%P</em> modifier is not supported in the Mac OS X implementation of this function. </p> </div> </dd> </dt> <dt> <span class="term"><em><code class="parameter">timestamp</code></em></span><dd> <p class="para"> The optional <em><code class="parameter">timestamp</code></em> parameter is an <span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span> Unix timestamp that defaults to the current local time if a <em><code class="parameter">timestamp</code></em> is not given. In other words, it defaults to the value of <span class="function"><a href="function.time.html" class="function">time()</a></span>. </p></dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.strftime-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns a string formatted according <em><code class="parameter">format</code></em> using the given <em><code class="parameter">timestamp</code></em> or the current local time if no timestamp is given. Month and weekday names and other language-dependent strings respect the current locale set with <span class="function"><a href="function.setlocale.html" class="function">setlocale()</a></span>. </p> </div> <div class="refsect1 errors" id="refsect1-function.strftime-errors"> <h3 class="title">Errors/Exceptions</h3> <p class="para"> Every call to a date/time function will generate a <strong><code>E_NOTICE</code></strong> if the time zone is not valid, and/or a <strong><code>E_STRICT</code></strong> or <strong><code>E_WARNING</code></strong> message if using the system settings or the <var class="varname"><var class="varname">TZ</var></var> environment variable. See also <span class="function"><a href="function.date-default-timezone-set.html" class="function">date_default_timezone_set()</a></span></p> <p class="para"> As the output is dependent upon the underlying C library, some conversion specifiers are not supported. On Windows, supplying unknown conversion specifiers will result in 5 <strong><code>E_WARNING</code></strong> messages and return <strong><code>FALSE</code></strong>. On other operating systems you may not get any <strong><code>E_WARNING</code></strong> messages and the output may contain the conversion specifiers unconverted. </p> </div> <div class="refsect1 changelog" id="refsect1-function.strftime-changelog"> <h3 class="title">Changelog</h3> <p class="para"> <table class="doctable informaltable"> <thead> <tr> <th>Version</th> <th>Description</th> </tr> </thead> <tbody class="tbody"> <tr><td>5.1.0</td><td><p class="para"> Now issues the <strong><code>E_STRICT</code></strong> and <strong><code>E_NOTICE</code></strong> time zone errors.</p></td></tr> </tbody> </table> </p> </div> <div class="refsect1 examples" id="refsect1-function.strftime-examples"> <h3 class="title">Examples</h3> <p class="para"> This example will work if you have the respective locales installed in your system. <div class="example" id="example-2318"> <p><strong>Example #1 <span class="function"><strong>strftime()</strong></span> locale examples</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />setlocale</span><span style="color: #007700">(</span><span style="color: #0000BB">LC_TIME</span><span style="color: #007700">, </span><span style="color: #DD0000">"C"</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">strftime</span><span style="color: #007700">(</span><span style="color: #DD0000">"%A"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">setlocale</span><span style="color: #007700">(</span><span style="color: #0000BB">LC_TIME</span><span style="color: #007700">, </span><span style="color: #DD0000">"fi_FI"</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">strftime</span><span style="color: #007700">(</span><span style="color: #DD0000">" in Finnish is %A,"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">setlocale</span><span style="color: #007700">(</span><span style="color: #0000BB">LC_TIME</span><span style="color: #007700">, </span><span style="color: #DD0000">"fr_FR"</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">strftime</span><span style="color: #007700">(</span><span style="color: #DD0000">" in French %A and"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">setlocale</span><span style="color: #007700">(</span><span style="color: #0000BB">LC_TIME</span><span style="color: #007700">, </span><span style="color: #DD0000">"de_DE"</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">strftime</span><span style="color: #007700">(</span><span style="color: #DD0000">" in German %A.\n"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> <p class="para"> <div class="example" id="example-2319"> <p><strong>Example #2 ISO 8601:1988 week number example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">/* December 2002 / January 2003<br />ISOWk M Tu W Thu F Sa Su<br />----- ----------------------------<br />51 16 17 18 19 20 21 22<br />52 23 24 25 26 27 28 29<br />1 30 31 1 2 3 4 5<br />2 6 7 8 9 10 11 12<br />3 13 14 15 16 17 18 19 */<br /><br />// Outputs: 12/28/2002 - %V,%G,%Y = 52,2002,2002<br /></span><span style="color: #007700">echo </span><span style="color: #DD0000">"12/28/2002 - %V,%G,%Y = " </span><span style="color: #007700">. </span><span style="color: #0000BB">strftime</span><span style="color: #007700">(</span><span style="color: #DD0000">"%V,%G,%Y"</span><span style="color: #007700">, </span><span style="color: #0000BB">strtotime</span><span style="color: #007700">(</span><span style="color: #DD0000">"12/28/2002"</span><span style="color: #007700">)) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Outputs: 12/30/2002 - %V,%G,%Y = 1,2003,2002<br /></span><span style="color: #007700">echo </span><span style="color: #DD0000">"12/30/2002 - %V,%G,%Y = " </span><span style="color: #007700">. </span><span style="color: #0000BB">strftime</span><span style="color: #007700">(</span><span style="color: #DD0000">"%V,%G,%Y"</span><span style="color: #007700">, </span><span style="color: #0000BB">strtotime</span><span style="color: #007700">(</span><span style="color: #DD0000">"12/30/2002"</span><span style="color: #007700">)) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Outputs: 1/3/2003 - %V,%G,%Y = 1,2003,2003<br /></span><span style="color: #007700">echo </span><span style="color: #DD0000">"1/3/2003 - %V,%G,%Y = " </span><span style="color: #007700">. </span><span style="color: #0000BB">strftime</span><span style="color: #007700">(</span><span style="color: #DD0000">"%V,%G,%Y"</span><span style="color: #007700">,</span><span style="color: #0000BB">strtotime</span><span style="color: #007700">(</span><span style="color: #DD0000">"1/3/2003"</span><span style="color: #007700">)) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Outputs: 1/10/2003 - %V,%G,%Y = 2,2003,2003<br /></span><span style="color: #007700">echo </span><span style="color: #DD0000">"1/10/2003 - %V,%G,%Y = " </span><span style="color: #007700">. </span><span style="color: #0000BB">strftime</span><span style="color: #007700">(</span><span style="color: #DD0000">"%V,%G,%Y"</span><span style="color: #007700">,</span><span style="color: #0000BB">strtotime</span><span style="color: #007700">(</span><span style="color: #DD0000">"1/10/2003"</span><span style="color: #007700">)) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /><br /><br /></span><span style="color: #FF8000">/* December 2004 / January 2005<br />ISOWk M Tu W Thu F Sa Su<br />----- ----------------------------<br />51 13 14 15 16 17 18 19<br />52 20 21 22 23 24 25 26<br />53 27 28 29 30 31 1 2<br />1 3 4 5 6 7 8 9<br />2 10 11 12 13 14 15 16 */<br /><br />// Outputs: 12/23/2004 - %V,%G,%Y = 52,2004,2004<br /></span><span style="color: #007700">echo </span><span style="color: #DD0000">"12/23/2004 - %V,%G,%Y = " </span><span style="color: #007700">. </span><span style="color: #0000BB">strftime</span><span style="color: #007700">(</span><span style="color: #DD0000">"%V,%G,%Y"</span><span style="color: #007700">,</span><span style="color: #0000BB">strtotime</span><span style="color: #007700">(</span><span style="color: #DD0000">"12/23/2004"</span><span style="color: #007700">)) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Outputs: 12/31/2004 - %V,%G,%Y = 53,2004,2004<br /></span><span style="color: #007700">echo </span><span style="color: #DD0000">"12/31/2004 - %V,%G,%Y = " </span><span style="color: #007700">. </span><span style="color: #0000BB">strftime</span><span style="color: #007700">(</span><span style="color: #DD0000">"%V,%G,%Y"</span><span style="color: #007700">,</span><span style="color: #0000BB">strtotime</span><span style="color: #007700">(</span><span style="color: #DD0000">"12/31/2004"</span><span style="color: #007700">)) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Outputs: 1/2/2005 - %V,%G,%Y = 53,2004,2005<br /></span><span style="color: #007700">echo </span><span style="color: #DD0000">"1/2/2005 - %V,%G,%Y = " </span><span style="color: #007700">. </span><span style="color: #0000BB">strftime</span><span style="color: #007700">(</span><span style="color: #DD0000">"%V,%G,%Y"</span><span style="color: #007700">,</span><span style="color: #0000BB">strtotime</span><span style="color: #007700">(</span><span style="color: #DD0000">"1/2/2005"</span><span style="color: #007700">)) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Outputs: 1/3/2005 - %V,%G,%Y = 1,2005,2005<br /></span><span style="color: #007700">echo </span><span style="color: #DD0000">"1/3/2005 - %V,%G,%Y = " </span><span style="color: #007700">. </span><span style="color: #0000BB">strftime</span><span style="color: #007700">(</span><span style="color: #DD0000">"%V,%G,%Y"</span><span style="color: #007700">,</span><span style="color: #0000BB">strtotime</span><span style="color: #007700">(</span><span style="color: #DD0000">"1/3/2005"</span><span style="color: #007700">)) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> <p class="para"> <div class="example" id="example-2320"> <p><strong>Example #3 Cross platform compatible example using the <em>%e</em> modifier</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /><br /></span><span style="color: #FF8000">// Jan 1: results in: '%e%1%' (%%, e, %%, %e, %%)<br /></span><span style="color: #0000BB">$format </span><span style="color: #007700">= </span><span style="color: #DD0000">'%%e%%%e%%'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Check for Windows to find and replace the %e <br />// modifier correctly<br /></span><span style="color: #007700">if (</span><span style="color: #0000BB">strtoupper</span><span style="color: #007700">(</span><span style="color: #0000BB">substr</span><span style="color: #007700">(</span><span style="color: #0000BB">PHP_OS</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">3</span><span style="color: #007700">)) == </span><span style="color: #DD0000">'WIN'</span><span style="color: #007700">) {<br /> </span><span style="color: #0000BB">$format </span><span style="color: #007700">= </span><span style="color: #0000BB">preg_replace</span><span style="color: #007700">(</span><span style="color: #DD0000">'#(?<!%)((?:%%)*)%e#'</span><span style="color: #007700">, </span><span style="color: #DD0000">'\1%#d'</span><span style="color: #007700">, </span><span style="color: #0000BB">$format</span><span style="color: #007700">);<br />}<br /><br />echo </span><span style="color: #0000BB">strftime</span><span style="color: #007700">(</span><span style="color: #0000BB">$format</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> <p class="para"> <div class="example" id="example-2321"> <p><strong>Example #4 Display all known and unknown formats.</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">// Describe the formats.<br /></span><span style="color: #0000BB">$strftimeFormats </span><span style="color: #007700">= array(<br /> </span><span style="color: #DD0000">'A' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'A full textual representation of the day'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'B' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'Full month name, based on the locale'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'C' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'Two digit representation of the century (year divided by 100, truncated to an integer)'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'D' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'Same as "%m/%d/%y"'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'E' </span><span style="color: #007700">=> </span><span style="color: #DD0000">''</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'F' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'Same as "%Y-%m-%d"'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'G' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'The full four-digit version of %g'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'H' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'Two digit representation of the hour in 24-hour format'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'I' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'Two digit representation of the hour in 12-hour format'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'J' </span><span style="color: #007700">=> </span><span style="color: #DD0000">''</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'K' </span><span style="color: #007700">=> </span><span style="color: #DD0000">''</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'L' </span><span style="color: #007700">=> </span><span style="color: #DD0000">''</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'M' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'Two digit representation of the minute'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'N' </span><span style="color: #007700">=> </span><span style="color: #DD0000">''</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'O' </span><span style="color: #007700">=> </span><span style="color: #DD0000">''</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'P' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'lower-case "am" or "pm" based on the given time'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'Q' </span><span style="color: #007700">=> </span><span style="color: #DD0000">''</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'R' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'Same as "%H:%M"'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'S' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'Two digit representation of the second'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'T' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'Same as "%H:%M:%S"'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'U' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'Week number of the given year, starting with the first Sunday as the first week'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'V' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'ISO-8601:1988 week number of the given year, starting with the first week of the year with at least 4 weekdays, with Monday being the start of the week'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'W' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'A numeric representation of the week of the year, starting with the first Monday as the first week'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'X' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'Preferred time representation based on locale, without the date'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'Y' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'Four digit representation for the year'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'Z' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'The time zone offset/abbreviation option NOT given by %z (depends on operating system)'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'a' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'An abbreviated textual representation of the day'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'b' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'Abbreviated month name, based on the locale'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'c' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'Preferred date and time stamp based on local'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'d' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'Two-digit day of the month (with leading zeros)'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'e' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'Day of the month, with a space preceding single digits'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'f' </span><span style="color: #007700">=> </span><span style="color: #DD0000">''</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'g' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'Two digit representation of the year going by ISO-8601:1988 standards (see %V)'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'h' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'Abbreviated month name, based on the locale (an alias of %b)'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'i' </span><span style="color: #007700">=> </span><span style="color: #DD0000">''</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'j' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'Day of the year, 3 digits with leading zeros'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'k' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'Hour in 24-hour format, with a space preceding single digits'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'l' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'Hour in 12-hour format, with a space preceding single digits'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'m' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'Two digit representation of the month'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'n' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'A newline character ("\n")'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'o' </span><span style="color: #007700">=> </span><span style="color: #DD0000">''</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'p' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'UPPER-CASE "AM" or "PM" based on the given time'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'q' </span><span style="color: #007700">=> </span><span style="color: #DD0000">''</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'r' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'Same as "%I:%M:%S %p"'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'s' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'Unix Epoch Time timestamp'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'t' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'A Tab character ("\t")'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'u' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'ISO-8601 numeric representation of the day of the week'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'v' </span><span style="color: #007700">=> </span><span style="color: #DD0000">''</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'w' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'Numeric representation of the day of the week'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'x' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'Preferred date representation based on locale, without the time'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'y' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'Two digit representation of the year'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'z' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'Either the time zone offset from UTC or the abbreviation (depends on operating system)'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'%' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'A literal percentage character ("%")'</span><span style="color: #007700">,<br />);<br /><br /></span><span style="color: #FF8000">// Results.<br /></span><span style="color: #0000BB">$strftimeValues </span><span style="color: #007700">= array();<br /><br /></span><span style="color: #FF8000">// Evaluate the formats whilst suppressing any errors.<br /></span><span style="color: #007700">foreach(</span><span style="color: #0000BB">$strftimeFormats </span><span style="color: #007700">as </span><span style="color: #0000BB">$format </span><span style="color: #007700">=> </span><span style="color: #0000BB">$description</span><span style="color: #007700">){<br /> if (</span><span style="color: #0000BB">False </span><span style="color: #007700">!== (</span><span style="color: #0000BB">$value </span><span style="color: #007700">= @</span><span style="color: #0000BB">strftime</span><span style="color: #007700">(</span><span style="color: #DD0000">"%</span><span style="color: #007700">{</span><span style="color: #0000BB">$format</span><span style="color: #007700">}</span><span style="color: #DD0000">"</span><span style="color: #007700">))){<br /> </span><span style="color: #0000BB">$strftimeValues</span><span style="color: #007700">[</span><span style="color: #0000BB">$format</span><span style="color: #007700">] = </span><span style="color: #0000BB">$value</span><span style="color: #007700">;<br /> }<br />}<br /><br /></span><span style="color: #FF8000">// Find the longest value.<br /></span><span style="color: #0000BB">$maxValueLength </span><span style="color: #007700">= </span><span style="color: #0000BB">2 </span><span style="color: #007700">+ </span><span style="color: #0000BB">max</span><span style="color: #007700">(</span><span style="color: #0000BB">array_map</span><span style="color: #007700">(</span><span style="color: #DD0000">'strlen'</span><span style="color: #007700">, </span><span style="color: #0000BB">$strftimeValues</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">// Report known formats.<br /></span><span style="color: #007700">foreach(</span><span style="color: #0000BB">$strftimeValues </span><span style="color: #007700">as </span><span style="color: #0000BB">$format </span><span style="color: #007700">=> </span><span style="color: #0000BB">$value</span><span style="color: #007700">){<br /> echo </span><span style="color: #DD0000">"Known format : '</span><span style="color: #007700">{</span><span style="color: #0000BB">$format</span><span style="color: #007700">}</span><span style="color: #DD0000">' = "</span><span style="color: #007700">, </span><span style="color: #0000BB">str_pad</span><span style="color: #007700">(</span><span style="color: #DD0000">"'</span><span style="color: #007700">{</span><span style="color: #0000BB">$value</span><span style="color: #007700">}</span><span style="color: #DD0000">'"</span><span style="color: #007700">, </span><span style="color: #0000BB">$maxValueLength</span><span style="color: #007700">), </span><span style="color: #DD0000">" ( </span><span style="color: #007700">{</span><span style="color: #0000BB">$strftimeFormats</span><span style="color: #007700">[</span><span style="color: #0000BB">$format</span><span style="color: #007700">]}</span><span style="color: #DD0000"> )\n"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #FF8000">// Report unknown formats.<br /></span><span style="color: #007700">foreach(</span><span style="color: #0000BB">array_diff_key</span><span style="color: #007700">(</span><span style="color: #0000BB">$strftimeFormats</span><span style="color: #007700">, </span><span style="color: #0000BB">$strftimeValues</span><span style="color: #007700">) as </span><span style="color: #0000BB">$format </span><span style="color: #007700">=> </span><span style="color: #0000BB">$description</span><span style="color: #007700">){<br /> echo </span><span style="color: #DD0000">"Unknown format : '</span><span style="color: #007700">{</span><span style="color: #0000BB">$format</span><span style="color: #007700">}</span><span style="color: #DD0000">' "</span><span style="color: #007700">, </span><span style="color: #0000BB">str_pad</span><span style="color: #007700">(</span><span style="color: #DD0000">' '</span><span style="color: #007700">, </span><span style="color: #0000BB">$maxValueLength</span><span style="color: #007700">), (</span><span style="color: #0000BB">$description </span><span style="color: #007700">? </span><span style="color: #DD0000">" ( </span><span style="color: #007700">{</span><span style="color: #0000BB">$description</span><span style="color: #007700">}</span><span style="color: #DD0000"> )" </span><span style="color: #007700">: </span><span style="color: #DD0000">''</span><span style="color: #007700">), </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p>The above example will output something similar to:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> Known format : 'A' = 'Friday' ( A full textual representation of the day ) Known format : 'B' = 'December' ( Full month name, based on the locale ) Known format : 'H' = '11' ( Two digit representation of the hour in 24-hour format ) Known format : 'I' = '11' ( Two digit representation of the hour in 12-hour format ) Known format : 'M' = '24' ( Two digit representation of the minute ) Known format : 'S' = '44' ( Two digit representation of the second ) Known format : 'U' = '48' ( Week number of the given year, starting with the first Sunday as the first week ) Known format : 'W' = '48' ( A numeric representation of the week of the year, starting with the first Monday as the first week ) Known format : 'X' = '11:24:44' ( Preferred time representation based on locale, without the date ) Known format : 'Y' = '2010' ( Four digit representation for the year ) Known format : 'Z' = 'GMT Standard Time' ( The time zone offset/abbreviation option NOT given by %z (depends on operating system) ) Known format : 'a' = 'Fri' ( An abbreviated textual representation of the day ) Known format : 'b' = 'Dec' ( Abbreviated month name, based on the locale ) Known format : 'c' = '12/03/10 11:24:44' ( Preferred date and time stamp based on local ) Known format : 'd' = '03' ( Two-digit day of the month (with leading zeros) ) Known format : 'j' = '337' ( Day of the year, 3 digits with leading zeros ) Known format : 'm' = '12' ( Two digit representation of the month ) Known format : 'p' = 'AM' ( UPPER-CASE "AM" or "PM" based on the given time ) Known format : 'w' = '5' ( Numeric representation of the day of the week ) Known format : 'x' = '12/03/10' ( Preferred date representation based on locale, without the time ) Known format : 'y' = '10' ( Two digit representation of the year ) Known format : 'z' = 'GMT Standard Time' ( Either the time zone offset from UTC or the abbreviation (depends on operating system) ) Known format : '%' = '%' ( A literal percentage character ("%") ) Unknown format : 'C' ( Two digit representation of the century (year divided by 100, truncated to an integer) ) Unknown format : 'D' ( Same as "%m/%d/%y" ) Unknown format : 'E' Unknown format : 'F' ( Same as "%Y-%m-%d" ) Unknown format : 'G' ( The full four-digit version of %g ) Unknown format : 'J' Unknown format : 'K' Unknown format : 'L' Unknown format : 'N' Unknown format : 'O' Unknown format : 'P' ( lower-case "am" or "pm" based on the given time ) Unknown format : 'Q' Unknown format : 'R' ( Same as "%H:%M" ) Unknown format : 'T' ( Same as "%H:%M:%S" ) Unknown format : 'V' ( ISO-8601:1988 week number of the given year, starting with the first week of the year with at least 4 weekdays, with Monday being the start of the week ) Unknown format : 'e' ( Day of the month, with a space preceding single digits ) Unknown format : 'f' Unknown format : 'g' ( Two digit representation of the year going by ISO-8601:1988 standards (see %V) ) Unknown format : 'h' ( Abbreviated month name, based on the locale (an alias of %b) ) Unknown format : 'i' Unknown format : 'k' Unknown format : 'l' ( Hour in 12-hour format, with a space preceding single digits ) Unknown format : 'n' ( A newline character ("\n") ) Unknown format : 'o' Unknown format : 'q' Unknown format : 'r' ( Same as "%I:%M:%S %p" ) Unknown format : 's' ( Unix Epoch Time timestamp ) Unknown format : 't' ( A Tab character ("\t") ) Unknown format : 'u' ( ISO-8601 numeric representation of the day of the week ) Unknown format : 'v' </pre></div> </div> </div> </p> </div> <div class="refsect1 notes" id="refsect1-function.strftime-notes"> <h3 class="title">Notes</h3> <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara"> %G and %V, which are based on ISO 8601:1988 week numbers can give unexpected (albeit correct) results if the numbering system is not thoroughly understood. See %V examples in this manual page. </span> </p></blockquote> </div> <div class="refsect1 seealso" id="refsect1-function.strftime-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"><a href="http://strftime.net/" class="link external">» Online strftime() format design tool</a></li> <li class="member"> <span class="function"><a href="function.setlocale.html" class="function" rel="rdfs-seeAlso">setlocale()</a> - Set locale information</span></li> <li class="member"> <span class="function"><a href="function.mktime.html" class="function" rel="rdfs-seeAlso">mktime()</a> - Get Unix timestamp for a date</span></li> <li class="member"> <span class="function"><a href="function.strptime.html" class="function" rel="rdfs-seeAlso">strptime()</a> - Parse a time/date generated with strftime</span></li> <li class="member"> <span class="function"><a href="function.gmstrftime.html" class="function" rel="rdfs-seeAlso">gmstrftime()</a> - Format a GMT/UTC time/date according to locale settings</span></li> <li class="member"><a href="http://www.opengroup.org/onlinepubs/007908799/xsh/strftime.html" class="link external">» Open Group specification of <span class="function"><strong>strftime()</strong></span></a></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.mktime.html">mktime</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.strptime.html">strptime</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>