Convert UTC dates to local time in PHP

前端 未结 10 1595
青春惊慌失措
青春惊慌失措 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:44

    Given a local timezone, such as 'America/Denver', you can use DateTime class to convert UTC timestamp to the local date:

    $timestamp = *********;
    $date = new DateTime("@" . $timestamp);
    $date->setTimezone(new DateTimeZone('America/Denver'));
    echo $date->format('Y-m-d H:i:s');
    

提交回复
热议问题