2017-07-28 02:43
浏览 50


So I understand how to use mktime() to create a date based on the current date/time:

date("Y-m-d H:i:s", mktime(date("H"), date("i"), date("s"), date("m"), date("d"), date("Y")+1

This creates a date exactly one year from now.

But how would I do this if I wanted to find out the date one year ahead of some fixed date? e.g. what will the date be 1 year in the future of the date 2017-10-01 23:59:59

图片转代码服务由CSDN问答提供 功能建议

所以我理解如何使用 mktime()创建基于当前的日期 日期/时间:

date(“Ymd H:i:s”,mktime(日期(“​​H”),日期(“i”),日期(“s”) ),日期(“m”),日期(“d”),日期(“Y”)+ 1

这将在一年之后创建一个日期。< / p>

但是,如果我想在某个固定日期之前一年找出日期,我该怎么办呢?例如,日期<1> 2017年的日期是什么? 2017 -10-01 23:59:59

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doukanzhuo4297
    doukanzhuo4297 2017-07-28 03:10

    You should use DateTime class. Nevertheless, this answer your question:

    $time = strtotime('27-07-2017');
    $date = date( 'Y-m-d H:i:s', mktime( date('H', $time), date('i', $time), date('s', $time), date('m', $time), date('d', $time), date('Y', $time)+1 ) );
    点赞 评论