首页 > 后端开发 > php教程 > php 获取昨天 今天 明天的时间

php 获取昨天 今天 明天的时间

WBOY
发布: 2016-07-28 08:29:01
原创
1294 人浏览过

php

比如,今天是2102年11月2号,那么php要获取2102年11月2号的时间戳是怎么办的呢?

代码:echostrtotime(date('Y-m-d')),'
';

 

获取明天凌晨的时间戳

代码:echostrtotime(date('Y-m-d',strtotime('+1 day'))),'
';

 

附上测试代码:

echo strtotime('2012-11-2'),'
';
echo strtotime('2012-11-2 00:00:00'),'
';
echo strtotime(date('Y-m-d')),'
';
echo date('Y-m-d H:i:s',strtotime(date('Y-m-d'))),'
';
echo strtotime(date('Y-m-d',strtotime('+1 day'))),'
';
echo ( strtotime(date('Y-m-d',strtotime('+1 day'))) -strtotime(date('Y-m-d')) )/3600;


<span>date_default_timezone_set</span><span>(</span><span>'</span><span>PRC</span><span>'</span><span>)</span><span>; </span><span>//</span><span>默认时区     </span><span>echo</span><span>"</span><span>今天:</span><span>"</span><span>,</span><span>date</span><span>(</span><span>"</span><span>Y-m-d</span><span>"</span><span>,</span><span>time</span><span>(</span><span>)</span><span>)</span><span>,</span><span>"</span><span><br></span><span>"</span><span>;     
</span><span>echo</span><span>"</span><span>今天:</span><span>"</span><span>,</span><span>date</span><span>(</span><span>"</span><span>Y-m-d</span><span>"</span><span>,</span><span>strtotime</span><span>(</span><span>"</span><span>18 june 2008</span><span>"</span><span>)</span><span>)</span><span>,</span><span>"</span><span><br></span><span>"</span><span>;     
</span><span>echo</span><span>"</span><span>昨天:</span><span>"</span><span>,</span><span>date</span><span>(</span><span>"</span><span>Y-m-d</span><span>"</span><span>,</span><span>strtotime</span><span>(</span><span>"</span><span>-1 day</span><span>"</span><span>)</span><span>)</span><span>, </span><span>"</span><span><br></span><span>"</span><span>;     
</span><span>echo</span><span>"</span><span>明天:</span><span>"</span><span>,</span><span>date</span><span>(</span><span>"</span><span>Y-m-d</span><span>"</span><span>,</span><span>strtotime</span><span>(</span><span>"</span><span>+1 day</span><span>"</span><span>)</span><span>)</span><span>, </span><span>"</span><span><br></span><span>"</span><span>;     
</span><span>echo</span><span>"</span><span>一周后:</span><span>"</span><span>,</span><span>date</span><span>(</span><span>"</span><span>Y-m-d</span><span>"</span><span>,</span><span>strtotime</span><span>(</span><span>"</span><span>+1 week</span><span>"</span><span>)</span><span>)</span><span>, </span><span>"</span><span><br></span><span>"</span><span>;     
</span><span>echo</span><span>"</span><span>一周零两天四小时两秒后:</span><span>"</span><span>,</span><span>date</span><span>(</span><span>"</span><span>Y-m-d G:H:s</span><span>"</span><span>,</span><span>strtotime</span><span>(</span><span>"</span><span>+1 week 2 days 4 hours 2 seconds</span><span>"</span><span>)</span><span>)</span><span>, </span><span>"</span><span><br></span><span>"</span><span>;     
</span><span>echo</span><span>"</span><span>下个星期四:</span><span>"</span><span>,</span><span>date</span><span>(</span><span>"</span><span>Y-m-d</span><span>"</span><span>,</span><span>strtotime</span><span>(</span><span>"</span><span>next Thursday</span><span>"</span><span>)</span><span>)</span><span>, </span><span>"</span><span><br></span><span>"</span><span>;     
</span><span>echo</span><span>"</span><span>上个周一:</span><span>"</span><span>.</span><span>date</span><span>(</span><span>"</span><span>Y-m-d</span><span>"</span><span>,</span><span>strtotime</span><span>(</span><span>"</span><span>last Monday</span><span>"</span><span>)</span><span>)</span><span>.</span><span>"</span><span><br></span><span>"</span><span>;     
</span><span>echo</span><span>"</span><span>一个月前:</span><span>"</span><span>.</span><span>date</span><span>(</span><span>"</span><span>Y-m-d</span><span>"</span><span>,</span><span>strtotime</span><span>(</span><span>"</span><span>last month</span><span>"</span><span>)</span><span>)</span><span>.</span><span>"</span><span><br></span><span>"</span><span>;     
</span><span>echo</span><span>"</span><span>一个月后:</span><span>"</span><span>.</span><span>date</span><span>(</span><span>"</span><span>Y-m-d</span><span>"</span><span>,</span><span>strtotime</span><span>(</span><span>"</span><span>+1 month</span><span>"</span><span>)</span><span>)</span><span>.</span><span>"</span><span><br></span><span>"</span><span>;     
</span><span>echo</span><span>"</span><span>十年后:</span><span>"</span><span>.</span><span>date</span><span>(</span><span>"</span><span>Y-m-d</span><span>"</span><span>,</span><span>strtotime</span><span>(</span><span>"</span><span>+10 year</span><span>"</span><span>)</span><span>)</span><span>.</span><span>"</span><span><br></span><span>"</span><span>;  </span>
登录后复制

以上就介绍了 php 获取昨天 今天 明天的时间,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板