2011-07-19 29 views

回答

20
$newDate = strtotime('+1 month',$startDate); 

使用strtotime()你可以通過它「+ 1月」添加上下文敏感的一個月。

2

豈不

strtotime('+1 month', $value_from_db); 

工作?

7

我會用strtotime()功能,增加+1 month到您的時間戳:

$future = strtotime('+1 month', $current_time); 


隨着strtotime(),你不必去思考自己喜歡關於「某月AVEC東西30天,和其他人有31「,或」2月有時有28天,有時29「。

畢竟,一個月增加的日期是有點困難,添加30 * 24 * 3600數秒


您也可以與DateTime類工作,方法如DateTime::modify()DateTime::add()

+0

謝謝,我沒有想清楚。出於某種原因,我一直在思考strtotime()只允許一個參數。 – FinalForm

+0

huhu ^^沒問題:-) –

2

取決於數據庫。

(不知道別人,對不起)

當然也有在PHP strtotime('+1 month', $current_time);。當然,strtotime非常容易,你可能會認爲它是作弊的;-)。

0

如何像:

tm *currTime = localtime(timestamp); 

currTime->tm_mon++; 

timestamp = mktime(currTime); 
相關問題