在PHP中增加日期的最简单方法? [英] Simplest way to increment a date in PHP?
本文介绍了在PHP中增加日期的最简单方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
2007-02-28
,我可以写的最简单的代码是将其转换为 2007-03-01
?现在我只是使用 strtotime()
,然后添加 24 * 60 * 60
,然后使用 date()
,但只是想知道是否有更干净,更简单或更聪明的方法。解决方案
一个干净的方式 要使用 strtotime()
$ date = strtotime(+ 1 day,strtotime(2007-02-28));
echo date(Y-m-d,$ date);
将给你2007-03-01
Say I have a string coming in, "2007-02-28"
, what's the simplest code I could write to turn that into "2007-03-01"
? Right now I'm just using strtotime()
, then adding 24*60*60
, then using date()
, but just wondering if there is a cleaner, simpler, or more clever way of doing it.
解决方案
A clean way is to use strtotime()
$date = strtotime("+1 day", strtotime("2007-02-28"));
echo date("Y-m-d", $date);
Will give you the 2007-03-01
这篇关于在PHP中增加日期的最简单方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文