Given a time, how can I find the time one month ago

后端 未结 7 1546
梦如初夏
梦如初夏 2021-01-13 08:16

Given a time, how can I find the time one month ago.

7条回答
  •  失恋的感觉
    2021-01-13 08:33

    We can achieve same by using PHP's modern date handling. This will require PHP 5.2 or better.

    // say its "2015-11-17 03:27:22"
    $dtTm = new DateTime('-1 MONTH', new DateTimeZone('America/Los_Angeles')); // first argument uses strtotime parsing
    echo $dtTm->format('Y-m-d H:i:s'); // "2015-10-17 03:27:22"
    

    Hope this adds some more info for this question.

提交回复
热议问题