douzhangbao2187
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
    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

    点赞 评论
  • dongliqian6245
    dongliqian6245 2016-12-21 08:50

    You should change Time Zone on yours server.

    点赞 评论
  • dougou3871
    dougou3871 2016-12-21 08:52

    Is the timezone of your system correctly set? If yes, try to set it again or use an other NTP server

    How to set timezone with Linux (tried on Ubuntu Server):

    dpkg-reconfigure tzdata
    
    点赞 评论

相关推荐