老莫的笔记本  
  
请选择 进入手机版 | 继续访问电脑版
查看: 999|回复: 0

PHP 时间戳与日期的相互转换

[复制链接]

662

主题

878

帖子

5115

积分

超级版主

Rank: 8Rank: 8

积分
5115
发表于 2018-8-14 22:23:52 | 显示全部楼层 |阅读模式
时间戳转日期 date()  【参数需要区分大小写 否则会有 24 和 12 的不同】
  1. var_dump(date('Y-m-d H:i:s', 1502204401)); //H 24小时制 2017-08-08 23:00:01
  2. var_dump(date('Y-m-d h:i:s', 1502204401)); //h 12小时制 2017-08-08 11:00:01
复制代码

日期转时间戳 strtotime()
  1. <?php
  2. echo strtotime("now"), "\n";
  3. echo strtotime("10 September 2000"), "\n";
  4. echo strtotime("+1 day"), "\n";
  5. echo strtotime("+1 week"), "\n";
  6. echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n";
  7. echo strtotime("next Thursday"), "\n";
  8. echo strtotime("last Monday"), "\n";
  9. echo strtotime("20170808 23:00:01"), "\n";
  10. ?>
复制代码
参考地址:https://blog.csdn.net/foreverling_ling/article/details/76974627

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表