I'm using an API right now and it provides an epochTime. I've tried everything to convert this epochtime to date, but it doesn't seem to be working including $epoch_time / 1000
and then using the date()
function to convert it.
The epoch time looks something like this 1353430853299. Is there a way to do this? strtotime()
did not work either.
It seems that all of the other readings about epoch time are about changing date to epochtime, but I'm looking to go the other way around. Any help is greatly appreciated.
Because our Epoch time is specified in milliseconds, we may convert it to seconds. To convert milliseconds to seconds, first, divide the millisecond count by 1000. Later, we use DATEADD() to add the number of seconds since the epoch, which is January 1, 1970 and cast the result to retrieve the date since the epoch.
You can take an epoch time divided by 86400 (seconds in a day) floored and add 719163 (the days up to the year 1970) to pass to it. Awesome, this is as manual as it gets.
Definition and Usage. The time() function returns the current time in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).
January 1st, 1970 at 00:00:00 UTC is referred to as the Unix epoch. Early Unix engineers picked that date arbitrarily because they needed to set a uniform date for the start of time, and New Year's Day, 1970, seemed most convenient.
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
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With