svn: /phpdoc/en/trunk/reference/datetime/datetime/ createfromformat.xml

From: Date: Sun, 13 Sep 2009 09:14:40 +0000
Subject: svn: /phpdoc/en/trunk/reference/datetime/datetime/ createfromformat.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-4912@lists.php.net to get a copy of this message
torben Sun, 13 Sep 2009 09:14:40 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=288288 Log: More thorough explanation of the use of ! to select default values in the generated time. Changed paths: U phpdoc/en/trunk/reference/datetime/datetime/createfromformat.xml Modified: phpdoc/en/trunk/reference/datetime/datetime/createfromformat.xml =================================================================== --- phpdoc/en/trunk/reference/datetime/datetime/createfromformat.xml 2009-09-13 04:13:01 UTC (rev 288287) +++ phpdoc/en/trunk/reference/datetime/datetime/createfromformat.xml 2009-09-13 09:14:40 UTC (rev 288288) @@ -30,6 +30,30 @@ <para> Format accepted by <function>date</function>. </para> + <para> + If <parameter>format</parameter> does not contain the character + <literal>!</literal> then portions of the date/time value + specified in <parameter>format</parameter> but not specified + in <parameter>time</parameter> will be set to the current + system time. + </para> + <para> + If <parameter>format</parameter> contains the + character <literal>!</literal>, then portions of the generated + time specified to the left-hand side of + the <literal>!</literal> in <parameter>format</parameter> will + be set to corresponding values from the Unix epoch. + </para> + <para> + If the first character of <parameter>format</parameter> + is <literal>!</literal>, then all portions of the date/time + value generated which are not specified in + <parameter>time</parameter> will be initialized to corresponding + values from the Unix epoch. + </para> + <para> + The Unix epoch is 1970-01-01 00:00:00. + </para> </listitem> </varlistentry> <varlistentry> @@ -50,15 +74,6 @@ </varlistentry> </variablelist> </para> - <para> - If the first character of <parameter>format</parameter> - is <literal>!</literal>, then portions of the date/time value - generated which are not specified in - <parameter>time</parameter> will be initialized to zero. If the - first character of <parameter>format</parameter> is - not <literal>!</literal> then portions of the date/time value - generated will be initialized to the current system time. - </para> </refsect1> <refsect1 role="returnvalues"> @@ -68,6 +83,50 @@ </para> </refsect1> + <refsect1 role="examples"> + &reftitle.examples; + <para> + <example> + <title>Using <literal>!</literal> to reset default date/time values</title> + <programlisting role="php"> +<![CDATA[ +<?php +echo "Current system date and time: " . date('Y-m-d H:i:s') . "\n"; + +$format = 'Y-m-d'; +$dt = DateTime::createFromFormat($format, '2009-02-03'); +echo "Format: $format; " . $dt->date . "\n"; + +$format = 'Y-m-d H:i:s'; +$dt = DateTime::createFromFormat($format, '2009-02-03 15:16:17'); +echo "Format: $format; " . $dt->date . "\n"; + +$format = 'Y-m-!d H:i:s'; +$dt = DateTime::createFromFormat($format, '2009-02-03 15:16:17'); +echo "Format: $format; " . $dt->date . "\n"; + +$format = '!Y-m-d'; +$dt = DateTime::createFromFormat($format, '2009-02-03'); +echo "Format: $format; " . $dt->date . "\n"; +?> +]]> + </programlisting> + <para> + The above example will output something like the following + (taking into account the current system time): + </para> + <screen> +<![CDATA[ +Current system date and time: 2009-09-13 01:04:03 +Format: Y-m-d; 2009-02-03 01:04:03 +Format: Y-m-d H:i:s; 2009-02-03 15:16:17 +Format: Y-m-!d H:i:s; 1970-01-03 15:16:17 +Format: !Y-m-d; 2009-02-03 00:00:00 +]]> + </screen> + </example> + </para> + </refsect1> </refentry> <!-- Keep this comment at the end of the file

« previous php.doc.cvs (#4912) next »