30

My computer local time is 12-03-2013 4:30pm.

My XAMPP date function prints the time as 12-03-2013 10:49:56.

How can I set the XAMPP server time to display the system time?

fragilewindows
  • 1,394
  • 1
  • 15
  • 26
Raja
  • 3,477
  • 12
  • 47
  • 89
  • 2
    What are you using to display the time? – Pekka Mar 12 '13 at 11:07
  • just php date function. The date function is displaying time: Mar 12, 2013 @ 11:31 (1363087870) where as my system it is Mar 12, 2013 @ 04:31. – Raja Mar 12 '13 at 11:32
  • Then it's a timezone issue. It wasn't clear from your initial question where you said it's a difference between 4:30 and 10:49. – Pekka Mar 12 '13 at 11:33

6 Answers6

57

Go to C:\xampp\php\php.ini, or your custom path where php.ini is, open it.

Look for the following: date.timezone = "Europe/Warsaw". Probably You have different value than my Europe/Warsaw. So search just string: date.timezone.

Change value Europe/Warsaw to the proper value, for example date.timezone = "Asia/Kolkata"

If someone's looking for his location, check valid values http://php.net/manual/en/timezones.php

Don't forget to restart your XAMPP.

Damonsson
  • 1,532
  • 14
  • 25
4

At your XAMPP you can change the php.ini and search

date.timezone

and change it to your prefer timezone

date.timezone = Asia/Jakarta

That's for XAMPP. And if you can't change the web server time at your remote server, try put this date_default_timezone_set() function at your php. Like this :

<?php date_default_timezone_set('Asia/Jakarta'); ?>
PutihTua
  • 112
  • 2
4

For others who are confused on what timezone (date.timezone) they should use (just like me a while ago), please refer to this manual from PHP

http://php.net/manual/en/timezones.php

Hope this helps.

niq
  • 107
  • 9
1

You have to define the timezone accordingly

date-default-timezone-set('GMT');

More read here

But I would suggest use mysql now() or curdate() to take the server time.

Sudip Pal
  • 2,041
  • 1
  • 13
  • 16
0

No need to change xampp's php.ini file. Add date_default_timezone_set() function before taking the current time.

date_default_timezone_set('Asia/Kolkata');
echo date("Y-m-d H:i:s");

Use this way because if you are hosting your website the the time will be displayed according to the host server. So use this method to get away from future errors.

Jinoy Varghese
  • 169
  • 1
  • 9
0

I suggest to use

date_default_timezone_set('UTC');

for your PHP application. It gives you the same time on all servers.

I have a CI application and its host to the server so apache is following other timezones and in local its follows differently.

I add date_default_timezone_set('UTC'); in my config.php file and working like champ.

Atul Baldaniya
  • 761
  • 8
  • 14