Reputation: 1167
In my particular case, both the server and the client are the same computer, I'm on localhost. When i echo out the date from the date() function, it displays a totally wrong value, a 11 hours earlier time. I also tried gmdate(), but it displays the date in AM not PM. Is there any way to change the apache server time, so everytime I get it in php, it displays the same as the time on my computer?
EDIT: Sorry for the late edit. I have already set the timezone in the php.ini but it still doesn't work. And I'm sure that my timezone is correct, since I got it from the manual and checked from phpinfo().
Upvotes: 20
Views: 117884
Reputation: 65
This can be changed in the php.ini
:
xampp/php/php.ini
. date.timezone=Europe/Berlin
and change it to your timezone.date.timezone=Africa/Nairobi
. Upvotes: 1
Reputation: 998
Open the php.ini under /etc/php.ini .
Uncomment this line and add your continent and the main city. Here is an example which works for Germany (Deutschland).
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = Europe/Berlin
See the website http://php.net/manual/de/timezones.php for all timezones in German.
Save the file php.ini. And restart the apache. Mageia LINUX uses this:
systemctl restart httpd.service
Upvotes: 18
Reputation: 2161
You need to do this in your php.ini file. I am on windows and run WAMP so my php.ini location is at: c:/wamp/bin/apache/Apache2.2.21/bin/
You then open that file and the default is set to: date.timezone = UTC
You would change this value for whatever timezone you want...
For a full list of timezones supported, you can visit: http://php.net/manual/en/timezones.php
Upvotes: 10
Reputation: 6228
I believe you are looking for: date_default_timezone_set ( string $timezone_identifier )
You can also set this in your php.ini config.
Upvotes: 17