tags:

views:

251

answers:

4

So the clock is 18:37 right now in sweden but it prints out 16:37 why is that?

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

What can be wrong?

A: 

It is possible that your server is located in a time that is 2 hour back from you.

You can use this page of the documentation to fix the timezone issue.

Chacha102
+4  A: 

Your date.timezone setting in your php.ini file is incorrect. Make sure that it is set to the proper value for your timezone:

date.timezone = Europe/Stockholm

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

date_default_timezone_set('Europe/Stockholm');

For a list of supported timezones, refer to the PHP Documentation.


If it still doesn't work, make sure your server is set to the proper timezone. If you've set the time manually and the timezone is incorrect (but since the time has been corrected manually it still shows the proper time), PHP has no way to get the UTC time properly and therefore returns the incorrect time.

Andrew Moore
Do you ever take a break?
Chacha102
Unfortunately for you, no I don't.
Andrew Moore
I'm catching up to you on the PHP stats board though.
Chacha102
Pot, meet kettle?
zombat
A: 

Try a line like this:

date_default_timezone_set('America/New_York');

Except, y'know, for Sweden.

dreeves
A: 

Is there any way of doing the equivalent of date_default_timezone_set() in PHP 4.x?

Chris J