date() has a problem?
Moderator: General Moderators
date() has a problem?
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
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
- andym01480
- Forum Contributor
- Posts: 390
- Joined: Wed Apr 19, 2006 5:01 pm
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
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.
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);
?>