代码之家  ›  专栏  ›  技术社区  ›  Aaranihlus

将天/周添加到格式化日期

php
  •  -1
  • Aaranihlus  · 技术社区  · 8 年前

    我的日期格式如下:Ymd

    $quote_start_date = $job['quote_authorised'];
    
    $newdate = date($quote_start_date, strtotime('+5 weeks'));
    

    然而,新的日期是相同的,向这样的格式的日期添加周的最简单方法是什么?

    3 回复  |  直到 8 年前
        1
  •  1
  •   HostFission    8 年前

    第二个参数 date 从新纪元开始需要秒。只需在时间的基础上增加5周,即:

    $newdate = date($format, strtotime($quote_start_date) + (5 * 7 * 24 * 60 * 60));
    

    $newdate = date($format, strtotime($quote_start_date) + 3024000);
    
        2
  •  1
  •   kinggs    8 年前

    的第一个参数 date

    $quote_start_date = $job['quote_authorised'];
    $newdate = date("Ymd", strtotime('+5 weeks', strtotime($quote_start_date)));
    

    更有效的方法是对一周的秒数使用固定值,而不依赖于PHP解析额外的秒数 strtotime 功能:

    $quote_start_date = $job['quote_authorised'];
    $newdate = date("Ymd", strtotime($quote_start_date) + 3024000);
    
        3
  •  0
  •   Minar_Mnr    8 年前

     $date = new Date();
     $nextDate = new Date($date.setTime( $date.getTime() + 1 * 86400000 ));
     // here 1 is number of day .
    
    推荐文章