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

From: Date: Sat, 24 Apr 2010 14:29:29 +0000
Subject: svn: /phpdoc/en/trunk/reference/datetime/datetime/ construct.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-6431@lists.php.net to get a copy of this message
danielc Sat, 24 Apr 2010 14:29:29 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=298431 Log: Combine and enhance examples. Move timestamp text from example to parameter and reword it. Changed paths: U phpdoc/en/trunk/reference/datetime/datetime/construct.xml Modified: phpdoc/en/trunk/reference/datetime/datetime/construct.xml =================================================================== --- phpdoc/en/trunk/reference/datetime/datetime/construct.xml 2010-04-24 13:32:30 UTC (rev 298430) +++ phpdoc/en/trunk/reference/datetime/datetime/construct.xml 2010-04-24 14:29:29 UTC (rev 298431) @@ -28,6 +28,10 @@ <para> String in a format accepted by <function>strtotime</function>. </para> + <para> + To use a UNIX timestamp, put a <literal>@</literal> on the + front of the timestamp string. + </para> </listitem> </varlistentry> <varlistentry> @@ -59,29 +63,38 @@ <programlisting role="php"> <![CDATA[ <?php -date_default_timezone_set('Europe/London'); +// Specified date/time in your computer's time zone. +$date = new DateTime('2000-01-01'); +echo $date->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"; ?> ]]> </programlisting> - </example> - - <example> - <title>Creating <classname>DateTime</classname> from a UNIX timestamp</title> - <para> - To create a <classname>DateTime</classname> object from a UNIX timestamp - use the <function>strtotime</function> <literal>@</literal> keyword. - </para> - <programlisting role="php"> + &example.outputs.similar; + <screen> <![CDATA[ -<?php -$timestamp = $_SERVER["REQUEST_TIME"]; -$dt = new DateTime("@$timestamp"); -?> +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 ]]> - </programlisting> + </screen> </example> </refsect1>

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