如何正确设置在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 :/

当我将时区设置为当前位置时(例如:Nairobi GMT +3) 然后询问时间 使用日期('Ym-d'),我得到的分钟值不正确。 即如果它是11:03 AM它显示11:15 AM(所以+ 12分钟差异)。 p>

以下是使用的代码。 很基本的。 完成工作。 p>

  date_default_timezone_set(“Africa / Nairobi”);  
 // echo date_default_timezone_get();  
echo date('H:i:s'); 
  code>  pre> 
 
 

此时间差异仅发生在我的客户端服务器中。 在其他测试服务器中,它提供准确的时间。 即上午11:03将显示上午11:03。 p>

我是否还需要更改php.ini中的时区? p>

编辑: strong> p>

  1. 该项目不在localhost中。 li>
  2. 之前的时间输出& 在时区设置相同之后:/ li> ol> div>

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

ntpdate -s time.nist.gov

what's the output of date before you set the timezone?

What's the ouput of

print_r(get_defined_vars())

Likely the server system time is ahead 12 minutes