Heim >Backend-Entwicklung >PHP-Tutorial >php 获取昨天 今天 明天的时间

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

WBOY
WBOYOriginal
2016-07-28 08:29:011295Durchsuche

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教程有兴趣的朋友有所帮助。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn