PHP: add seconds to a date

前端 未结 9 1532
庸人自扰
庸人自扰 2020-12-04 01:22

I have $adate; which contains:

Tue Jan 4 07:59:59 2011

I want to add to this date the following:

$duration=674         


        
9条回答
  •  生来不讨喜
    2020-12-04 01:57

    Given the fact that $adate is a timestamp (if that's the case), you could do something like this:

    $duration = 674165;
    $result_date = strtotime(sprintf('+%d seconds', $duration), $adate);
    echo date('Y-m-d H:i:s', $result_date);
    

提交回复
热议问题