mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
Add an example of howto create a DateTime object from a unix timestamp
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@295817 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
75c3613337
commit
772012190e
1 changed files with 14 additions and 0 deletions
|
@ -63,6 +63,20 @@ date_default_timezone_set('Europe/London');
|
|||
$datetime = new DateTime('2008-08-03 14:52:10');
|
||||
echo $datetime->format(DATE_ATOM);
|
||||
?>
|
||||
]]>
|
||||
</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">
|
||||
<![CDATA[
|
||||
$timestamp = $_SERVER["REQUEST_TIME"];
|
||||
$dt = new DateTime("@$timestamp");
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
|
|
Loading…
Reference in a new issue