menislici
menislici

Reputation: 1167

How to change the time in apache server so it matches the computer's time (PHP)?

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

Answers (4)

Njoroge Mathu
Njoroge Mathu

Reputation: 65

This can be changed in the php.ini:

  • If using xampp, open xampp/php/php.ini.
  • Look for the line date.timezone=Europe/Berlin and change it to your timezone.
    In my case I changed to date.timezone=Africa/Nairobi.
  • Save and restart apache.

Upvotes: 1

Franz Holzinger
Franz Holzinger

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

Justin
Justin

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

Andy Baird
Andy Baird

Reputation: 6228

I believe you are looking for: date_default_timezone_set ( string $timezone_identifier )

Link

You can also set this in your php.ini config.

Upvotes: 17

Related Questions