php - One Hour Earlier Than Given Datetime

前端 未结 5 546
不思量自难忘°
不思量自难忘° 2020-12-20 14:16

I\'m having a problem here..

Supposed I have this kind of datetime.


$date = strtotime($date);

I need this to be converted into t

5条回答
  •  無奈伤痛
    2020-12-20 14:54

    86400 seconds is one DAY, not one hour.

    The output of strtotime() is a unix timestamp. 3600 seconds earlier is that timestamp minus one hour. So:

    $date = strtotime($somestring);
    
    $hourago = $date - 3600;
    

    Or, depending on the original format of $somestring:

    $hourago = strtotime($somestring . " - 1 hour");
    

    And don't forget about date_default_timezone_set()

提交回复
热议问题