douzhangbao2187 2016-12-21 08:45
浏览 43
已采纳

根据PHP中的当前时区,日期时间不准确

I need to set timezone in my laravel project but it's not giving exact same time. There is a difference in current time (checking via google) and the time my code is showing. My code is below:

date_default_timezone_set($generalSettings[0]->timeZone);
// $generalSettings[0]->timeZone = "America/Denver"
echo date("Y-m-d h:m:s");
exit;

It's showing "2016-12-21 01:12:05" while current time in "Time in Denver, CO, USA" 1:40 A.M. What I'm missing here that should display exactly same date time. Thanks!

  • 写回答

3条回答 默认 最新

  • duanou2016 2016-12-21 08:58
    关注

    You have to set your default timezone php function, so if yours is Denver you have something like :

    date_default_timezone_set('America/Denver');
    $date = date('m/d/Y h:i:s a', time());
    echo $date;
    

    Hope it helps you, anyway check it out :

    Here

    Edit : If you want it on server have to work on : php.ini

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?