php中两种方法获取时间戳有差异,为什么?
本文介绍了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
解决方案
strtotime(date("Y-m-d h:m:s"))
应该是:
strtotime(date("Y-m-d h:i:s"))
这篇关于php中两种方法获取时间戳有差异,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文