douhui3760 2016-09-01 08:15
浏览 89
已采纳

如何正确设置在PHP中使用日期('Y-m-d')时给出的时间?

When I set the timezone to my current location (eg: Nairobi GMT +3) And then ask for the time using date('Y-m-d'), I get an incorrect value for minutes. i.e if it`s 11:03 AM it shows 11:15 AM (so +12 minutes difference).

Below is the code used. Pretty basic. Gets the job done.

date_default_timezone_set("Africa/Nairobi"); 
//echo date_default_timezone_get(); 
echo date('H:i:s');

Also this time difference only occurs in my client`s server. In other test servers , it provides accurate time. i.e 11:03 AM will show 11:03 AM.

Am I required to change the timezone in php.ini as well?

EDIT:

  1. The project isn`t in localhost.
  2. The output of time before & after the timezone set is the same :/
  • 写回答

3条回答 默认 最新

  • dongshuobei1037 2016-09-01 08:31
    关注

    Probably your system time is 12 minutes ahead. If you are under linux, try

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

报告相同问题?

悬赏问题

  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了