当天的第二天: $x2_year = 2009; 
$x2_month = 1; 
$x2_day = 1; 用什么办法换算最快捷? 

解决方案 »

  1.   

    $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); 
      

  2.   

    最笨的方法当然是:$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;
      

  3.   

    $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); 
    }
      

  4.   


    $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
    )
      

  5.   

    使用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'];
    ?>
      

  6.   


    应为这个,首个参数不能要!
    $date = getdate( mktime(0,0,0,$x1_month,$x1_day,$x1_year)+3600*24); 
      

  7.   

    当天: $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));
      

  8.   

    把已知的时间转成时间戳
    然后用date(time()+86400)输出
    86400是一天的描述
      

  9.   


    <?php
    $date = new DateTime("2008-12-31");
    $date->modify("+1 day");
    echo $date->format("Y-m-d");?> 
      

  10.   


    echo date('Y-m-d',strtotime("+1 day",strtotime('2008-12-31')));
      

  11.   

    楼上那种方法是最方便的,还可以计算一个月,一年后的日期。用参数+1 month或+1 year还有中方法就是将你的年月日转化为unix时间戳,就是1970年到现在的秒数。然后加上86400秒(1天的秒数),然后再转成年月日就可以了。
      

  12.   

    赞同6楼的方法把当天的日期换算成时间戳,然后+上一天的秒数 再转换成日期都是php的内置函数,代码比较少
      

  13.   

    +1 day 本身就提供了此操作参数...还转来转去的...
      

  14.   

    +1 day 方法好,加秒数就不是很容易理解了,如果秒比较多的话。
      

  15.   

    <?
    $x1_year = 2008; 
    $x1_month = 12; 
    $x1_day = 31; echo date("Y-m-d",strtotime("+1 days",strtotime($x1_year."-".$x1_month."-".$x1_day)));
    ?>