Reputation: 11682
Any idea why this
strtotime('1356532858') //Wed, 26 Dec 2012 14:40:58 GMT
returns 28043243813
while
strtotime('1356055871') //Fri, 21 Dec 2012 02:11:11 GMT
returns false
?
I'm searching for a solution where I can translate any common date string into a valid timestamp. Unfortunately there are some (valid) timestamps included as well
Upvotes: 1
Views: 135
Reputation: 24661
Try putting a '@' in front of your timestamp. This will instruct strtotime
that this is a timestamp in Unix format:
var_dump(strtotime('@1356055871'));
Upvotes: 1
Reputation: 4937
maybe you could try to use strtotime
only if string is not 10-digit?
$str = '1356055871';
$timestamp = (preg_match('/\d{10}/',$str,$match))?(int)$str:strtotime($str);
echo $timestamp;
Regarding the question why you receive a value on first execution, and false
in second one, this is because 1356532858
is interpreted as some valid date, although is not what you're expecting:
echo date("Y-m-d H:i:s",strtotime('1356532858'));
// outputs: 2858-08-27 13:56:53
strtotime
can accept your timestamp, but should have a leading @
:
echo date("Y-m-d H:i:s",strtotime('@1356532858'));
// outputs: 2012-12-26 15:40:58
Upvotes: 1