Page 1 of 1

date() has a problem?

Posted: Fri May 19, 2006 2:10 am
by bangkok
I have a php code:
echo date("h:i:s A");

date() always generates time advanced to one hour comparing to that of the computer.
For example, the time of website is 01:48:58 PM. the function outputs : 02:48:58 PM.

Please tell me the problem and solution
Thank

Posted: Fri May 19, 2006 2:12 am
by andym01480
What time zone is the server in compared to your computer?

Posted: Fri May 19, 2006 2:19 am
by RobertGonzalez
Had that problem with a server hosted on the east coast. I am on the west coast so my server time was always three hours ahead.

Posted: Fri May 19, 2006 2:43 am
by bangkok
I run on the localhost (my computer is also server) but the time is different.

Posted: Fri May 19, 2006 3:07 am
by RobertGonzalez
Have you checked your computer time?

Posted: Fri May 19, 2006 3:46 am
by bangkok
My computer time is correct

Posted: Fri May 19, 2006 4:33 am
by onion2k
If you're using PHP 5.1 then there's a timezone setting in php.ini .. your's might be wrong.

Posted: Tue May 23, 2006 1:26 am
by bangkok
I changed in php.ini
date.timezone = Asia/Saigon
and it's correct.

Thank

Posted: Tue May 23, 2006 3:12 am
by Benjamin
If the time is right on the pc, and the timezone offset is correct in php.ini, then perhaps you are using GMT time rather than actual time. Either that or there is an error in your code. I would encourage you to read the PHP documentation regarding all the functions you are currently using to calculate the time.

Posted: Tue May 23, 2006 5:48 am
by opensme
This should work though I haven't tested it. Find out your offset from GMT time and change $offset...

Code: Select all

<?php
$offset = +5;
$zone = 3600 * $offest;
echo gmdate("h:i:s A", time() + $zone);
?>