Convert timestamp with timezone to readable date
I want to convert the timestamp to readable format, timestamp: / Date (1434434419100-0400) / but not sure how to deal with it along with the timezone problem.
date('Y-m-d H:i:s', substr($editDate, -20, -7))
thank
With timestamp, do you mean Unix epoch time?
When working with times and dates, I always find something useful at http://www.epochconverter.com .
For PHP see Programming> Epoch in PHP
Using the function date
.
$epoch = 1340000000;
echo date('r', $epoch); // output as RFC 2822 date - returns local time
echo gmdate('r', $epoch); // returns GMT/UTC time
Using the class DateTime
$epoch = 1344988800;
$dt = new DateTime("@$epoch"); // convert UNIX timestamp to PHP DateTime
echo $dt->format('Y-m-d H:i:s'); // output = 2012-08-15 00:00:00
Time zone setting
If you are using PHP 5.1 or higher use date_default_timezone_set to set / unset your timezone. PHP timezone handling takes care of daylight saving time ( PHP timezone list ).
The value you give - 1434434419100-0400
is definitely not a standard formatted timestamp. See w3.org and wikipedia for an overview of what is considered standard. The closest I could find is that it is an epoch 1434434419
(i.e. Tue, June 16, 2015 06:00:19 GMT) plus 100-0400
. Don't know what it means 100
, but -0400
may indicate UTC-04: 00 .
First, set the time zone on the date_default_timezone_set("Europe/Helsinki");
second use echo date('m/d/Y H:i:s', 1299446702);
, where 1299446702
there istime();
You can convert timestamp to date as follows.
$date = new DateTime("@".$timestamp);
To deal with the timezone refer to this