首頁 >後端開發 >php教程 >php 取得昨天 今天 明天的時間

php 取得昨天 今天 明天的時間

WBOY
WBOY原創
2016-07-28 08:29:011295瀏覽

php

例如,今天是2102年11月2號,那麼php要取得2102年11月2號的時間戳是怎麼辦的呢?

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

 

 

 

 

 


 



 



 


<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>
取得明天凌晨的時間戳記

代碼:echostrtotime(date('Y-m-d',strtotime('+1 day'))),'';  附上測試程式碼:echo strtotime('2012-11-2'),'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 天'))),'';echo ( strtotime(date('Y-m-d',strtotime('+1 day'))) -strtotime(date('Y-m-d')) )/3600; 以上就介紹了 php 獲取昨天 今天的時間,包括了方面的內容,希望對PHP教程有興趣的朋友有所幫助。
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn