Watches Php 2 hours ago

So, the clock at 18:37 is now in Sweden, but it prints out 16:37, why is this?

$timestamp = time(); date('M d, H:i', $timestamp) 

What could be wrong?

+4
source share
3 answers

Invalid date.timezone parameter in your php.ini . Make sure your time zone is set to the appropriate value:

 date.timezone = Europe/Stockholm 

If you do not have access to the php.ini , you can use date_default_timezone_set() to set it at runtime:

 date_default_timezone_set('Europe/Stockholm'); 

See the PHP documentation for a list of supported time zones.


If it still does not work, make sure that your server has the correct time zone. If you set the time manually and the time zone is incorrect (but since the time was corrected manually, it still shows the correct time), PHP is not able to correctly get the UTC time and, therefore, returns the wrong time.

+7
source

Your server may be 2 hours away from you.

You can use this documentation page to fix the time zone problem.

+1
source

Try the following line:

 date_default_timezone_set('America/New_York'); 

Except, you know, for Sweden.

0
source

All Articles