mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 08:58:56 +00:00
Combine and enhance examples. Move timestamp text from example to parameter and reword it.
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@298431 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
b058ed9338
commit
96dc0a070e
1 changed files with 30 additions and 17 deletions
|
@ -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>
|
||||
|
||||
|
|
Loading…
Reference in a new issue