Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

epoch date conversion

Tags:

php

timestamp

I'm trying to convert an epoch timestamp with php 5.3 with the following statement

date('d-m-Y',strtotime('1349042399999'));

to human readable format and getting wrong result: 01-01-1970what should return30-09-2012. I have been searching around and founding the following topic PHP strtotime returns a 1970 date when date column is null but did not help on my case.

like image 223
Kakuki Peter Avatar asked May 02 '26 06:05

Kakuki Peter


1 Answers

The reason for that is that there are milliseconds embedded in that timestamp, which causes it to go over the integer overflow limit.

chop the last 3 characters, and you're good to go:

$original_timestamp = "1349042399999";
$timestamp = (int) substr($original_timestamp,0,-3);

echo date('d-m-Y',$timestamp);
like image 161
Madara's Ghost Avatar answered May 03 '26 19:05

Madara's Ghost



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!