php中两种方法获取时间戳有差异,为什么?

尝试用php的两种方式获取当前的时间戳,存在差异,但是两个时间戳转换成时间确是想同的时间点,查了一下网络上的时间戳的单位是秒。为什么会这样?


$currentDay = getdate();
//var_dump($currentDay);
//2.1 获取当前的日期
//echo $currentDay["year"]."-".$currentDay["mon"]."-".$currentDay["mday"]."<br/>";
echo "时间戳为1:".strtotime(date("Y-m-d h:m:s"))."<br/>";
echo "时间戳为2:".$currentDay[0]."<br/>";
$time1 = strtotime(date("Y-m-d h:m:s"));
echo "不同的时间为:".date("Y-m-d H:m:s a",$currentDay[0])."--".date("Y-m-d H:m:s a",$time1);

输出结果为:
时间戳为1:1492131843
时间戳为2:1492134903
不同的时间为:2017-04-14 09:04:03 am--2017-04-14 09:04:03 am

阅读 5.2k
5 个回答
strtotime(date("Y-m-d h:m:s"))

应该是:

strtotime(date("Y-m-d h:i:s"))

建议楼主多读读php手册。链接

你自己写错了

新手上路,请多包涵

年月日 时分秒对应的是 Y-m-d h:i:s

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题