Create new DateTime object using a UNIX timestamp in PHP

Description

The following code shows how to create new DateTime object using a UNIX timestamp.

Example


<?php//from  w  ww. jav a 2 s . c  o m
// 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";

?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Data Types »




Array
Array Associative
Array Util
ArrayObject
Data Types
Date
Date Format
DateTime
Number
String
String Escape
String Filter
String HTML
String Type
Timezone