<?php
echo strtotime("2014-01-01 00:00:01")."<hr>";
// output is 1388516401
?>
如果可以反转,我很惊讶。我的意思是我可以将 1388516401 转换为 2014-01-01 00:00:01
。
我真正想知道的是,这种转换背后的逻辑是什么。 php 如何将日期转换为特定的整数。
最佳答案
是的,您可以将其转换回来。你可以试试:
date("Y-m-d H:i:s", 1388516401);
从日期到整数的转换背后的逻辑在 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 日 00:00:00 UTC 之后的 1,388,516,401 秒。
关于PHP 将整数转换为日期,strtotime 的反转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20617100/