How to increase time in php: first set the default time zone through "date_default_timezone_set"; then output tomorrow's time through "strtotime(' 1 day')"; finally modify the parameters to any number you want to increase.
php Add one day to a certain time? One hour? Time addition and subtraction
<?php date_default_timezone_set('PRC'); //默认时区 echo "今天:",date("Y-m-d",time()),"<br>"; echo "今天:",date("Y-m-d",strtotime("18 june 2008")),"<br>"; echo "昨天:",date("Y-m-d",strtotime("-1 day")),"<br>"; echo "明天:",date("Y-m-d",strtotime("+1 day")),"<br>"; echo "一周后:",date("Y-m-d",strtotime("+1 week")),"<br>"; echo "一周零两天四小时两秒后:",date("Y-m-d G:H:s",strtotime("+1 week 2 days 4 hours 2 seconds")), "<br>"; echo "下个星期四:",date("Y-m-d",strtotime("next Thursday")),"<br>"; echo "上个周一:".date("Y-m-d",strtotime("last Monday"))."<br>"; echo "一个月前:".date("Y-m-d",strtotime("last month"))."<br>"; echo "一个月后:".date("Y-m-d",strtotime("+1 month"))."<br>"; echo "十年后:".date("Y-m-d",strtotime("+10 year"))."<br>"; ?>
//strtotime可以接受第二个参数,类型timestamp,为指定日期 echo date('Y-m-d', strtotime ("+1 day", strtotime('2011-11-01'))),"\n";
<?php echo "今天:",date('Y-m-d H:i:s'),"<br>";//输出当前时间 echo "明天:",date('Y-m-d H:i:s',strtotime('+1 day'));//输出明天时间 //这里+1 day 可以修改参数1为任何想需要的数 day也可以改成year(年),month(月),hour(小时),minute(分),second(秒) //如: date('Y-m-d H:i:s',strtotime("+1 day +1 hour +1 minute"); ?>
Note: This method was tried after 1970, which is the scope of application of timestamps.
<?php //下面这些代码是一些常用的日期处理函数了,可以两个时间的日期加减,两日期之差,日期转换时间截等。 echo date('Y-m-d',strtotime('+1 d',strtotime('2009-07-08')));//日期天数相加函数 echo date("Y-m-d",'1246982400'); echo '<br>'; echo date("Y-m-d",'1279123200'); die(); $d = "2009-07-08 10:19:00"; echo date("Y-m-d",strtotime("$d +1 day")); //日期天数相加函数 function dateToTime($d){//把日期转换成时间堆截 $year=((int)substr("$d",0,4));//取得年份 $month=((int)substr("$d",5,2));//取得月份 $day=((int)substr("$d",8,2));//取得几号 return mktime(0,0,0,$month,$day,$year); } $Date_1="2009-07-08"; echo $Date_1+1; $Date_2="2009-06-08"; $Date_List_a1=explode("-",$Date_1); $Date_List_a2=explode("-",$Date_2); $d1=mktime(0,0,0,$Date_List_a1[1],$Date_List_a1[2],$Date_List_a1[0]); $d2=mktime(0,0,0,$Date_List_a2[1],$Date_List_a2[2],$Date_List_a2[0]); $Days=round(($d1-$d2)/3600/24); echo "两日期之前相差有$Days 天"; ?>
Recommended: "PHP Tutorial"
The above is the detailed content of How to increase time in php. For more information, please follow other related articles on the PHP Chinese website!