tags:

views:

55

answers:

4

I am using date() function it getting the date and time as per my given format but the time its showing me is 4 hours forward than my current local machine time: This is my code

echo date("Y-m-d h:i:s", time());

Its showing me : 2009-10-28 08:47:42 Where as it should Disply : 2009-10-28 04:47:42

Any Idea whats wrong with this and why its showing different time.

+2  A: 

Make sure your time zone is set correctly:

e.g.

date_default_timezone_set('UTC');
kchau
That's likely to perpetuate the problem - using that value. However, setting the default time zone to an appropriate value is correct (just UTC is probably not correct).
Jonathan Leffler
Agreed. The timezone the author sets would be whatever is correct for their application.
kchau
A: 

Because you are in, probably, US/Eastern (America/New_York, currently EDT) time zone, but the PHP you are using is running in UTC. You need to ensure that the TZ variable is set in the PHP environment.

Jonathan Leffler
+1  A: 

it is likely giving you GMT, you need to set your timezone: e.g. date_default_timezone_set('America/Los_Angeles');

http://php.net/manual/en/function.date-default-timezone-set.php

Mike Valstar
I am in Kuala Lumpur Malaysia so what should be my time zone .
Talha Bin Shakir
http://php.net/manual/en/timezones.php should help you find yourself in there
Mike Valstar
+2  A: 

It's returning the timezone of your server, not your computer

try http://www.php.net/manual/en/function.date-default-timezone-set.php

Galen