PHP & MySQL: Converting Stored TIMESTAMP into User's Local Timezone

前端 未结 4 892
遇见更好的自我
遇见更好的自我 2020-12-09 11:12

So I have a site with a comments feature where the timestamp of the comment is stored in a MySQL database. From what I understand, the timestamp is converted to UTC when sto

4条回答
  •  余生分开走
    2020-12-09 11:56

    $timezone = new DateTimeZone('America/Vancouver');
    
    $date = new DateTime(date('m/d/Y h:i:s a', time()));
    $date->setTimeZone($timezone);
    echo $date->format('l F j Y g:i:s A')."\n";
    

    Replace new DateTime(date('m/d/Y h:i:s a', time())); with new DateTime("UTC Time");

    You can create a new DateTimeZone() object for each user input.

提交回复
热议问题