加入收藏 | 设为首页 | 会员中心 | 我要投稿 北几岛 (https://www.beijidao.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

PHP将整数转换为日期,反转strtotime

发布时间:2021-07-06 05:25:43 所属栏目:大数据 来源: https://www.jb51.cc
导读:?PHPecho strtotime("2014-01-01 00:00:01")."hr";// output is 1388516401? 如果它可以逆转,我会感到惊讶.我的意思是我可以将1388516401转换为2014-01-01 00:00:01. 我真正想知道的是,这种转换背后的逻辑是什么. PHP如何将日期转换为特定的整数. 解决方法:

<?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);

这个从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

(编辑:北几岛)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读