<?php
echo strtotime("2014-01-01 00:00:01")."<hr>";
// output is 1388516401
?>
I am surprised if it can be reverse. I mean can I convert 1388516401 to 2014-01-01 00:00:01
.
What I actually want to know is, what's the logic behind this conversion. How php convert date to a specific integer.
This question is related to
php
date
time
type-conversion
strtotime
The time() function displays the seconds between now and the unix epoch , 01 01 1970 (00:00:00 GMT). The strtotime() transforms a normal date format into a time() format. So the representation of that date into seconds will be : 1388516401
Source: http://www.php.net/time
Can you try this,
echo date("Y-m-d H:i:s", 1388516401);
As noted by theGame,
This means that you pass in a string value for the time, and optionally a value for the current time, which is a UNIX timestamp. The value that is returned is an integer which is a UNIX timestamp.
echo strtotime("2014-01-01 00:00:01");
This will return into the value 1388516401, which is the UNIX timestamp for the date 2014-01-01. This can be confirmed using the date() function as like below:
echo date('Y-m-d', 1198148400); // echos 2014-01-01
I guess you are asking why is 1388516401 equal to 2014-01-01...?
There is an historical reason for that. There is a 32-bit integer variable, called time_t
, that keeps the count of the time elapsed since 1970-01-01 00:00:00. Its value expresses time in seconds. This means that in 2014-01-01 00:00:01 time_t
will be equal to 1388516401.
This leads us for sure to another interesting fact... In 2038-01-19 03:14:07 time_t
will reach 2147485547, the maximum value for a 32-bit number. Ever heard about John Titor and the Year 2038 problem? :D
Source: Stackoverflow.com