How to adjust the time zone

I set the time zone of the clock server in Asia / Tokyo. However, although I made changes to php.ini and restarted httpd, it will not return the correct time. Time is 9 hours less than a year later. When I change the time zone of Europe / Berin, I see a change in time, but it also does not return the 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?

0
php vagrant
source share
4 answers

I finally found a way out. The reason the code above didn't work is because my system clock was wrong, so I ran the command below.

First I installed ntp.

 sudo yum -y install ntp 

Secondly, I got the correct time from ntp.

 sudo ntpdate ntp.nict.jp 

What is it. Thanks for the suggestions!

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

0
source share

Also restart apache after the change in php.ini .

Just try once

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

Demo here

+1
source share

First install 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:

 $time = getCurrentDateTime; 
0
source share

Try installing the Time Zone plugin for Vagrant :

 vagrant plugin install vagrant-timezone 

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

0
source share

All Articles