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条)

报告相同问题?

悬赏问题

  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”