DateInterval 怎么减少时间
程序员文章站
2022-04-26 08:17:40
...
DateInterval 如何减少时间
比如这个代码是获取当前时间加上3个小时,那么如何获取减少3个小时呢?
------解决方案--------------------
DateInterval::format() - Formats the interval
DateTime::add() - Adds an amount of days, months, years, hours, minutes and seconds to a DateTime object
DateTime::sub() - Subtracts an amount of days, months, years, hours, minutes and seconds from a DateTime object
比如这个代码是获取当前时间加上3个小时,那么如何获取减少3个小时呢?
- PHP code
(new \DateTime('NOW'))->add(new \DateInterval('PT3H'))
------解决方案--------------------
DateInterval::format() - Formats the interval
DateTime::add() - Adds an amount of days, months, years, hours, minutes and seconds to a DateTime object
DateTime::sub() - Subtracts an amount of days, months, years, hours, minutes and seconds from a DateTime object
相关文章
相关视频
下一篇: 分享一些前端面试题实例