0
votes

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?

4
Well what does it show for each of Europe/Berlin and Asia/Tokyo? Is it possible that the system clock is just wrong?Jon Skeet
@Jon Skeet When I set the timezone to Asia/Tokyo, it returned "2015/11/03 7:23:25" but the time in Tokyo at that time was 2015/11/03 16:23. When I set the timezone to Europe/Berlin, it returned "2015/11/02 23:34:10" but the time in Berlin at that time was 2015/11/03 08:34. It seems it is possible my system clock is wrong.Sho

4 Answers

1
votes

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

0
votes

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;
0
votes

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

0
votes

Try installing Time Zone plugin for Vagrant by:

vagrant plugin install vagrant-timezone

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