Convert UTC dates to local time in PHP

前端 未结 10 1616
青春惊慌失措
青春惊慌失措 2020-11-28 07:16

I\'m storing the UTC dates into the DB using:

$utc = gmdate(\"M d Y h:i:s A\");

and then I want to convert the saved UTC date to the client

10条回答
  •  无人及你
    2020-11-28 07:45

    Date arithmetic is not needed if you just want to display the same timestamp in different timezones:

    $format = "M d, Y h:ia";
    $timestamp = gmdate($format);
    
    date_default_timezone_set("UTC");
    $utc_datetime = date($format, $timestamp);
    
    date_default_timezone_set("America/Guayaquil");
    $local_datetime = date($format, $timestamp);
    

提交回复
热议问题