date() has a problem?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bangkok
Forum Newbie
Posts: 4
Joined: Fri May 19, 2006 1:51 am

date() has a problem?

Post 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
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Post by andym01480 »

What time zone is the server in compared to your computer?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
bangkok
Forum Newbie
Posts: 4
Joined: Fri May 19, 2006 1:51 am

Post by bangkok »

I run on the localhost (my computer is also server) but the time is different.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Have you checked your computer time?
bangkok
Forum Newbie
Posts: 4
Joined: Fri May 19, 2006 1:51 am

Post by bangkok »

My computer time is correct
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

If you're using PHP 5.1 then there's a timezone setting in php.ini .. your's might be wrong.
bangkok
Forum Newbie
Posts: 4
Joined: Fri May 19, 2006 1:51 am

Post by bangkok »

I changed in php.ini
date.timezone = Asia/Saigon
and it's correct.

Thank
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post 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.
opensme
Forum Newbie
Posts: 3
Joined: Mon May 22, 2006 8:25 am

Post 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);
?>
Post Reply