echo strtotime("2014-01-01 00:00:01")."
";
// output is 1388516401
?>
如果它可以逆转,我会感到惊讶.我的意思是我可以将1388516401转换为2014-01-01 00:00:01.
我真正想知道的是,这种转换背后的逻辑是什么. php如何将日期转换为特定的整数.
解决方法:
是的,你可以将其转换回来.你可以试试:
date("Y-m-d H:i:s", 1388516401);
这个从date转换为整数的逻辑在strtotime中用PHP解释:
The function expects to be given a string containing an English date format and will try to parse that format into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 UTC), relative to the timestamp given in now, or the current time if now is not supplied.
例如,strtotime(“1970-01-01 00:00:00”)给你0和strtotime(“1970-01-01 00:00:01”)给你1.
这意味着如果您打印strtotime(“2014-01-01 00:00:01”),它将输出1388516401,所以日期2014-01-01 00:00:01是1970年1月1日之后的1,388,516,401秒00 :00:00 UTC
标签:strtotime,php,date,time,type-conversion
来源: https://codeday.me/bug/20190930/1836669.html