- The format specifiers for createFromFormat and parse_from_format() are not

the same as date()'s. I've documented them now.


git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@306285 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Derick Rethans 2010-12-12 19:01:20 +00:00
parent fc99dbfc0a
commit ec7222dda3
2 changed files with 238 additions and 3 deletions

View file

@ -35,8 +35,243 @@
<term><parameter>format</parameter></term>
<listitem>
<para>
Format accepted by <function>date</function>.
The format that the passed in <type>string</type> should be in. See the
formatting options below. In most cases, the same letters as for the
<function>date</function> can be used.
</para>
<para>
<table>
<title>The following characters are recognized in the
<parameter>format</parameter> parameter string</title>
<tgroup cols="3">
<thead>
<row>
<entry><parameter>format</parameter> character</entry>
<entry>Description</entry>
<entry>Example parsable values</entry>
</row>
</thead>
<tbody>
<row>
<entry align="center"><emphasis>Day</emphasis></entry>
<entry>---</entry>
<entry>---</entry>
</row>
<row>
<entry><literal>d</literal> and <literal>j</literal></entry>
<entry>Day of the month, 2 digits with or without leading zeros</entry>
<entry>
<literal>01</literal> to <literal>31</literal> or
<literal>1</literal> to <literal>1</literal>
</entry>
</row>
<row>
<entry><literal>D</literal> and <literal>l</literal></entry>
<entry>A textual representation of a day</entry>
<entry>
<literal>Mon</literal> through <literal>Sun</literal> or
<literal>Sunday</literal> through <literal>Saturday</literal>
</entry>
</row>
<row>
<entry><literal>S</literal></entry>
<entry>English ordinal suffix for the day of the month, 2
characters. It's ignored while processing.</entry>
<entry>
<literal>st</literal>, <literal>nd</literal>, <literal>rd</literal> or
<literal>th</literal>.
</entry>
</row>
<row>
<entry><literal>z</literal></entry>
<entry>The day of the year (starting from 0)</entry>
<entry><literal>0</literal> through <literal>365</literal></entry>
</row>
<row>
<entry align="center"><emphasis>Month</emphasis></entry>
<entry>---</entry>
<entry>---</entry>
</row>
<row>
<entry><literal>F</literal> and <literal>M</literal></entry>
<entry>A textual representation of a month, such as January or Sept</entry>
<entry>
<literal>January</literal> through <literal>December</literal> or
<literal>Jan</literal> through <literal>Dec</literal>
</entry>
</row>
<row>
<entry><literal>m</literal> and <literal>n</literal></entry>
<entry>Numeric representation of a month, with or without leading zeros</entry>
<entry>
<literal>01</literal> through <literal>12</literal> or
<literal>1</literal> through <literal>12</literal>
</entry>
</row>
<row>
<entry align="center"><emphasis>Year</emphasis></entry>
<entry>---</entry>
<entry>---</entry>
</row>
<row>
<entry><literal>Y</literal></entry>
<entry>A full numeric representation of a year, 4 digits</entry>
<entry>Examples: <literal>1999</literal> or <literal>2003</literal></entry>
</row>
<row>
<entry><literal>y</literal></entry>
<entry>A two digit representation of a year</entry>
<entry>Examples: <literal>99</literal> or <literal>03</literal></entry>
</row>
<row>
<entry align="center"><emphasis>Time</emphasis></entry>
<entry>---</entry>
<entry>---</entry>
</row>
<row>
<entry><literal>a</literal> and <literal>A</literal></entry>
<entry>Ante meridiem and Post meridiem</entry>
<entry><literal>am</literal> or <literal>pm</literal></entry>
</row>
<row>
<entry><literal>g</literal> and <literal>h</literal></entry>
<entry>12-hour format of an hour with or without leading zero</entry>
<entry>
<literal>1</literal> through <literal>12</literal> or
<literal>01</literal> through <literal>12</literal>
</entry>
</row>
<row>
<entry><literal>G</literal> and <literal>H</literal></entry>
<entry>24-hour format of an hour with or without leading zeros</entry>
<entry>
<literal>0</literal> through <literal>23</literal> or
<literal>00</literal> through <literal>23</literal>
</entry>
</row>
<row>
<entry><literal>i</literal></entry>
<entry>Minutes with leading zeros</entry>
<entry><literal>00</literal> to <literal>59</literal></entry>
</row>
<row>
<entry><literal>s</literal></entry>
<entry>Seconds, with leading zeros</entry>
<entry><literal>00</literal> through <literal>59</literal></entry>
</row>
<row>
<entry><literal>u</literal></entry>
<entry>Microseconds (up to six digits)</entry>
<entry>Example: <literal>45</literal>, <literal>654321</literal></entry>
</row>
<row>
<entry align="center"><emphasis>Timezone</emphasis></entry>
<entry>---</entry>
<entry>---</entry>
</row>
<row>
<entry>
<literal>e</literal>, <literal>O</literal>,
<literal>P</literal> and <literal>T</literal>
</entry>
<entry>Timezone identifier, or difference to UTC in hours, or
difference to UTC with colon between hours and minutes, or timezone
abbreviation</entry>
<entry>Examples: <literal>UTC</literal>, <literal>GMT</literal>,
<literal>Atlantic/Azores</literal> or
<literal>+0200</literal></entry> or
<literal>+02:00</literal></entry> or
<literal>EST</literal>, <literal>MDT</literal>
</entry>
</row>
<row>
<entry align="center"><emphasis>Full Date/Time</emphasis></entry>
<entry>---</entry>
<entry>---</entry>
</row>
<row>
<entry><literal>U</literal></entry>
<entry>Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)</entry>
<entry>Example: <literal>1292177455</literal></entry>
</row>
<row>
<entry align="center"><emphasis>Whitespace and Separators</emphasis></entry>
<entry>---</entry>
<entry>---</entry>
</row>
<row>
<entry><literal> </literal> (space)</entry>
<entry>One space or one tab</entry>
<entry>Example: <literal> </literal></entry>
</row>
<row>
<entry><literal>#</literal></entry>
<entry>
One of the following separation symbol: <literal>;</literal>,
<literal>:</literal>, <literal>/</literal>, <literal>.</literal>,
<literal>,</literal>, <literal>-</literal>, <literal>(</literal> or
<literal>)</literal>
</entry>
<entry>Example: <literal>/</literal></entry>
</row>
<row>
<entry>
<literal>;</literal>,
<literal>:</literal>, <literal>/</literal>, <literal>.</literal>,
<literal>,</literal>, <literal>-</literal>, <literal>(</literal> or
<literal>)</literal>
</entry>
<entry>The specified character.</entry>
<entry>Example: <literal>-</literal></entry>
</row>
<row>
<entry><literal>?</literal></entry>
<entry>A random byte</entry>
<entry>Example: <literal>^</literal> (Be aware that for UTF-8
characracters you might need more than one <literal>?</literal>.
In this case, using <literal>*</literal> is probably what you want
instead)</entry>
</row>
<row>
<entry><literal>*</literal></entry>
<entry>Random bytes until the next separator or digit</entry>
<entry>Example: <literal>*</literal> in <literal>Y-*-d</literal> with
the string <literal>2009-aWord-08</literal> will match
<literal>aWord</literal></entry>
</row>
<row>
<entry><literal>!</literal></entry>
<entry>Resets all fields (year, month, day, hour, minute, second,
fraction and timzone information) to the Unix Epoch</entry>
<entry>Without <literal>!,</literal> all fields will be set to the
current date and time.</entry>
</row>
<row>
<entry><literal>|</literal></entry>
<entry>Resets all fields (year, month, day, hour, minute, second,
fraction and timzone information) to the Unix Epoch if they have
not been parsed yet</entry>
<entry><literal>Y-m-d|</literal> will set the year, month and day
to the information found in the string to parse, and sets the hour,
minute and second to 0.</entry>
</row>
<row>
<entry><literal>+</literal></entry>
<entry>If this format specifier is present, trailing data in the
string will not cause an error, but a warning instead</entry>
<entry>Use <method>DateTime::getLastErrors</method> to find out
whether trailing data was present.</entry>
</row>
</tbody>
</tgroup>
</table>
</para>
<para>
Unrecognized characters in the format string will cause the
parsing to fail and an error message is appended to the returned
structure. You can query error messages with
<method>DateTime::getLastErrors</method>.
</para>
<para>
If <parameter>format</parameter> does not contain the character
<literal>!</literal> then portions of the generated time which are not

View file

@ -4,7 +4,7 @@
<refentry xml:id="function.date-parse-from-format" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>date_parse_from_format</refname>
<refpurpose>Get info about given date</refpurpose>
<refpurpose>Get info about given date formarred according to the specified format</refpurpose>
</refnamediv>
<refsect1 role="description">
@ -27,7 +27,7 @@
<term><parameter>format</parameter></term>
<listitem>
<para>
Format accepted by <function>date</function> with some extras.
Format accepted by <function>DateTime::createFromFormat</function>.
</para>
</listitem>
</varlistentry>