diff --git a/reference/datetime/datetime/construct.xml b/reference/datetime/datetime/construct.xml index 745f5be033..e8d9119563 100644 --- a/reference/datetime/datetime/construct.xml +++ b/reference/datetime/datetime/construct.xml @@ -28,6 +28,10 @@ String in a format accepted by strtotime. + + To use a UNIX timestamp, put a @ on the + front of the timestamp string. + @@ -59,29 +63,38 @@ format('Y-m-d H:i:sP') . "\n"; -$datetime = new DateTime('2008-08-03 14:52:10'); -echo $datetime->format(DATE_ATOM); +// Specified date/time in the specified time zone. +$date = new DateTime('2000-01-01', new DateTimeZone('Pacific/Nauru')); +echo $date->format('Y-m-d H:i:sP') . "\n"; + +// Current date/time in your computer's time zone. +$date = new DateTime(); +echo $date->format('Y-m-d H:i:sP') . "\n"; + +// Current date/time in the specified time zone. +$date = new DateTime(null, new DateTimeZone('Pacific/Nauru')); +echo $date->format('Y-m-d H:i:sP') . "\n"; + +// Using a UNIX timestamp. Notice the result is in the UTC time zone. +$date = new DateTime('@946684800'); +echo $date->format('Y-m-d H:i:sP') . "\n"; ?> ]]> - - - - Creating <classname>DateTime</classname> from a UNIX timestamp - - To create a DateTime object from a UNIX timestamp - use the strtotime @ keyword. - - + &example.outputs.similar; + +2000-01-01 00:00:00-05:00 +2000-01-01 00:00:00+12:00 +2010-04-24 10:24:16-04:00 +2010-04-25 02:24:16+12:00 +2000-01-01 00:00:00+00:00 ]]> - +