PHP需要从DateTime中减去12小时30分钟 [英] PHP, need to subtract 12 hours and 30 minutes from a DateTime
本文介绍了PHP需要从DateTime中减去12小时30分钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个PHP DateTime
变量。
I have a PHP DateTime
variable.
如何在PHP运行时从此日期减少或减去12小时30分钟?
How can I reduce or subtract 12hours and 30 minutes from this date in at PHP runtime?
推荐答案
从PHP的DateTime中减去12小时30分钟:
Subtract 12 Hours and 30 minutes from a DateTime in PHP:
$date = new DateTime();
$tosub = new DateInterval('PT12H30M');
$date->sub($tosub);
P代表Period。 T代表Timespan。
The P stands for Period. The T stands for Timespan.
请参阅 DateTime , DateTime :: sub ,以及PHP手册中的 DateInterval 。当然,您必须将 DateTime
设置为适当的日期和时间。
See DateTime, DateTime::sub, and DateInterval in the PHP manual. You'll have to set the DateTime
to the appropriate date and time, of course.
这篇关于PHP需要从DateTime中减去12小时30分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文