PHP: 知道了年月日三个变量,如何换算出明天的年月日? 当天的第二天: $x2_year = 2009; $x2_month = 1; $x2_day = 1; 用什么办法换算最快捷? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 $tom_time=strtotime($x1_year.'-'.$x1_month.'-'.$x1_day)+3600*24;$x2_year = date('Y',$tom_time); $x2_month = date('m',$tom_time);$x2_day = date('d',$tom_time); 最笨的方法当然是:$xx_day_per_month=0;switch($x1_month){ case 1: case 3: case 5: case 7: case 8: case 10: case 12: $xx_day_per_month=31; break; case 4: case 6: case 9: case 11: $xx_day_per_month=30; default: if( ($x1_year % 4) == 0) $xx_day_per_month=29; else $xx_day_per_month=28;}if($x1_day<$xx_day_per_month){ $x1_day ++;}else{ $x1_day = 1; $x1_month ++; if($x1_month>12) { $x1_month=1; $x1_year++; }}$x2_day=$x1_day;$x2_year=$x1_year;$x2_month=$x1_month; $x1_year = 2008;$x1_month = 12;$x1_day = 31; getTomorrow($x1_year,$x1_month,$x1_day,$x2_year,$x2_month,$x2_day);echo "$x2_year-$x2_month-$x2_day";function getTomorrow($y,$m,$d,&$ry,&$rm,&$rd) { $t =strtotime("+1 day",strtotime("$y-$m-$d")); $ry = date('Y',$t); $rm = date('m',$t); $rd = date('d',$t); } $date = getdate("Y-m-d", mktime(0,0,0,$x1_month,$x1_day,$x1_year)+3600*24);print_r($date);输出类似:Array( [seconds] => 40 [minutes] => 58 [hours] => 21 [mday] => 17 [wday] => 2 [mon] => 6 [year] => 2003 [yday] => 167 [weekday] => Tuesday [month] => June [0] => 1055901520) 使用mktime根据当天的时间设置一个时间截,然后加上1天的秒数,这样就可以了:<?php$time = getdate(mktime(0,0,0,$x1_month,$x1_day+1,$x1_year));//创建今天的明天的时间截,用date重新格式化$x2_year=$time['year'];$x2_month = $time['mon'];$x2_day = $time['mday'];?> 应为这个,首个参数不能要!$date = getdate( mktime(0,0,0,$x1_month,$x1_day,$x1_year)+3600*24); 当天: $x1_year = 2008; $x1_month = 12; $x1_day = 31; 明天:$x2_year = date("Y",maketime(0,0,0,$x1_month,$x1_day+1,$x1_year));$x2_month = date("m",maketime(0,0,0,$x1_month,$x1_day+1,$x1_year));$x2_day = date("d",maketime(0,0,0,$x1_month,$x1_day+1,$x1_year)); 把已知的时间转成时间戳然后用date(time()+86400)输出86400是一天的描述 <?php$date = new DateTime("2008-12-31");$date->modify("+1 day");echo $date->format("Y-m-d");?> echo date('Y-m-d',strtotime("+1 day",strtotime('2008-12-31'))); 楼上那种方法是最方便的,还可以计算一个月,一年后的日期。用参数+1 month或+1 year还有中方法就是将你的年月日转化为unix时间戳,就是1970年到现在的秒数。然后加上86400秒(1天的秒数),然后再转成年月日就可以了。 赞同6楼的方法把当天的日期换算成时间戳,然后+上一天的秒数 再转换成日期都是php的内置函数,代码比较少 +1 day 本身就提供了此操作参数...还转来转去的... +1 day 方法好,加秒数就不是很容易理解了,如果秒比较多的话。 <?$x1_year = 2008; $x1_month = 12; $x1_day = 31; echo date("Y-m-d",strtotime("+1 days",strtotime($x1_year."-".$x1_month."-".$x1_day)));?> fopen()打开本地文件,老打不开。 php只能在本地服务器网站跟目录创建目录吗?不能在其它盘创建吗? php怎么可以来做软件呢? 一直迷惑…… 请问php中如何得到调用子网页的父网页文件名? [上海]Flash Action Script程序开发人员 求助大家用php正则匹配链接地址,标题,和图片 我在win98下调试的问题。 我的PHP程序在浏览器中显示中文显示的是乱码,何故? 抓取图片求助 域名解析+nginx问题,求大神来解答 PHP+MYSQL上传文章时,出现错误,好像是包含有特殊字符吧,请大家帮忙解决 求教
$x2_year = date('Y',$tom_time);
$x2_month = date('m',$tom_time);
$x2_day = date('d',$tom_time);
switch($x1_month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
$xx_day_per_month=31;
break;
case 4:
case 6:
case 9:
case 11:
$xx_day_per_month=30;
default:
if( ($x1_year % 4) == 0)
$xx_day_per_month=29;
else
$xx_day_per_month=28;
}
if($x1_day<$xx_day_per_month)
{
$x1_day ++;
}
else
{
$x1_day = 1;
$x1_month ++;
if($x1_month>12)
{
$x1_month=1;
$x1_year++;
}
}
$x2_day=$x1_day;
$x2_year=$x1_year;
$x2_month=$x1_month;
$x1_month = 12;
$x1_day = 31;
getTomorrow($x1_year,$x1_month,$x1_day,$x2_year,$x2_month,$x2_day);
echo "$x2_year-$x2_month-$x2_day";function getTomorrow($y,$m,$d,&$ry,&$rm,&$rd) {
$t =strtotime("+1 day",strtotime("$y-$m-$d"));
$ry = date('Y',$t);
$rm = date('m',$t);
$rd = date('d',$t);
}
$date = getdate("Y-m-d", mktime(0,0,0,$x1_month,$x1_day,$x1_year)+3600*24);print_r($date);输出类似:Array
(
[seconds] => 40
[minutes] => 58
[hours] => 21
[mday] => 17
[wday] => 2
[mon] => 6
[year] => 2003
[yday] => 167
[weekday] => Tuesday
[month] => June
[0] => 1055901520
)
<?php
$time = getdate(mktime(0,0,0,$x1_month,$x1_day+1,$x1_year));//创建今天的明天的时间截,用date重新格式化
$x2_year=$time['year'];
$x2_month = $time['mon'];
$x2_day = $time['mday'];
?>
应为这个,首个参数不能要!
$date = getdate( mktime(0,0,0,$x1_month,$x1_day,$x1_year)+3600*24);
$x1_month = 12;
$x1_day = 31; 明天:$x2_year = date("Y",maketime(0,0,0,$x1_month,$x1_day+1,$x1_year));
$x2_month = date("m",maketime(0,0,0,$x1_month,$x1_day+1,$x1_year));
$x2_day = date("d",maketime(0,0,0,$x1_month,$x1_day+1,$x1_year));
然后用date(time()+86400)输出
86400是一天的描述
<?php
$date = new DateTime("2008-12-31");
$date->modify("+1 day");
echo $date->format("Y-m-d");?>
echo date('Y-m-d',strtotime("+1 day",strtotime('2008-12-31')));
$x1_year = 2008;
$x1_month = 12;
$x1_day = 31; echo date("Y-m-d",strtotime("+1 days",strtotime($x1_year."-".$x1_month."-".$x1_day)));
?>