Rumah > pembangunan bahagian belakang > tutorial php > php 获取昨天 今天 明天的时间

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

WBOY
Lepaskan: 2016-07-28 08:29:01
asal
1294 orang telah melayarinya

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>
Salin selepas log masuk

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

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan