本文實(shí)例講述了PHP中時(shí)間加減函數(shù)strtotime用法。分享給大家供大家參考,具體如下:
時(shí)間加減
<?php//獲取本地 提取年份+1$date=date("Y-m-d",mktime(0,0,0,date("m") ,date("d"),date("Y")+1));?>如果要獲取數(shù)據(jù)庫中的時(shí)間應(yīng)該如何處理呢?在PHP文檔中找到了一個(gè)很好的函數(shù)strtotime,可以對(duì)時(shí)間進(jìn)行加減:
	int strtotime ( string time [, int now] )
返回類型 int
函數(shù)可用于時(shí)間轉(zhuǎn)換和加減。
<?php//date()格式化時(shí)間返回String類型。//加一年$date_year = date('Y-m-d',strtotime("$date + 1 year"));echo $date_year;//加一天$date_tomorrow = date('Y-m-d',strtotime("2009-05-26 + 1 day"));echo $date_tomorrow;//加一周$date_week = date('Y-m-d',strtotime("$date + 1 week"));echo $date_week;?>希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答
圖片精選