Convert UTC dates to local time in PHP

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

    I store date in the DB in UTC format but then I show them to the final user in their local timezone

    // retrieve
    $d = (new \DateTime($val . ' UTC'))->format('U');
    return date("Y-m-d H:i:s", $d);
    

提交回复
热议问题