From 6bd8161553051690fce3e98756471e72b38666d8 Mon Sep 17 00:00:00 2001 From: Torben Wilson Date: Sun, 13 Sep 2009 09:14:40 +0000 Subject: [PATCH] More thorough explanation of the use of ! to select default values in the generated time. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@288288 c90b9560-bf6c-de11-be94-00142212c4b1 --- .../datetime/datetime/createfromformat.xml | 77 ++++++++++++++++--- 1 file changed, 68 insertions(+), 9 deletions(-) diff --git a/reference/datetime/datetime/createfromformat.xml b/reference/datetime/datetime/createfromformat.xml index 31599105c6..cdfbfc5007 100644 --- a/reference/datetime/datetime/createfromformat.xml +++ b/reference/datetime/datetime/createfromformat.xml @@ -30,6 +30,30 @@ Format accepted by date. + + If format does not contain the character + ! then portions of the date/time value + specified in format but not specified + in time will be set to the current + system time. + + + If format contains the + character !, then portions of the generated + time specified to the left-hand side of + the ! in format will + be set to corresponding values from the Unix epoch. + + + If the first character of format + is !, then all portions of the date/time + value generated which are not specified in + time will be initialized to corresponding + values from the Unix epoch. + + + The Unix epoch is 1970-01-01 00:00:00. + @@ -50,15 +74,6 @@ - - If the first character of format - is !, then portions of the date/time value - generated which are not specified in - time will be initialized to zero. If the - first character of format is - not ! then portions of the date/time value - generated will be initialized to the current system time. - @@ -68,6 +83,50 @@ + + &reftitle.examples; + + + Using <literal>!</literal> to reset default date/time values + +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"; +?> +]]> + + + The above example will output something like the following + (taking into account the current system time): + + + + + + +