php把时间变成整数,PHP将整数转换为日期,反转strtotime

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值