How to Correct Timezone

风流意气都作罢 提交于 2019-12-25 14:13:25

问题


I set my vagrant server's timezone to Asia/Tokyo. However, though I made change in php.ini and restarted httpd, it doesn't return the correct time. The time is 9 hours late from correct time. When I change the time zone Europe/Berin, I see the time changes but it also doesn't return correct time.

Here is my php code

echo('<pre>');
var_dump(date("Y/m/d G:i:s"));
echo('</pre>');
exit;

php.ini

date.timezone = Asia/Tokyo

Are there any suggestions?


回答1:


Also restart your apache once you have changed in php.ini.

Just try this once,

<?php
    date_default_timezone_set("Asia/Tokyo");
    var_dump(date("Y/m/d G:i:s"));
    exit;

Demo Here




回答2:


first Set it like this:

date_default_timezone_set("Asia/Tokyo");

Make a simple function:

function getCurrentDateTime(){
    return date("Y:m:d H:i:s");
}

And call it anywhere you need:

$time = getCurrentDateTime;



回答3:


I finally found the way out. The reason the code above didn't work was that my system clock was wrong, so I executed the command bellow.

First, I installed ntp.

sudo yum -y install ntp

Second, I got the correct time from ntp.

sudo ntpdate ntp.nict.jp

That's it. Thanks for suggestions!

A helpful link: http://pyoonn.hatenablog.com/entry/2015/01/06/121925




回答4:


Try installing Time Zone plugin for Vagrant by:

vagrant plugin install vagrant-timezone

and use set config.timezone.value in your Vagrantfile.



来源:https://stackoverflow.com/questions/33493221/how-to-correct-timezone

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!