Convert Epoch Time to Date PHP

There are a couple different ways you can do this.

First off, what you've got there is a Unix Epoch time. (1/1/1970), that makes everything MUCH easier.

In PHP, try

$epoch = 1344988800;
$dt = new DateTime("@$epoch");
echo $dt->format('Y-m-d H:i:s');

To display your date

OR

If you want the long RFC232 date:

echo date('r', $epoch);

$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 

More: http://www.epochconverter.com/programming/functions-php.php


<?php
$epoch = '1353429562';

date_default_timezone_set('GMT');
echo date('Y-m-d H:i:s', $epoch);

Fixed it using substr($epoch, 0, 10) and then used the date function for anyone wondering about the 13 digit epoch times.

Here is a sample code:

echo date("Y-m-d H:i:s", substr("1477020641000", 0, 10));
// Result: 2016-10-20 20:30:41

Tags:

Time

Php

Epoch