Time not displaying properly with php 5.1.2

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

User avatar
sarav_dude
Forum Newbie
Posts: 24
Joined: Sun Apr 30, 2006 8:40 am
Location: India
Contact:

Time not displaying properly with php 5.1.2

Post by sarav_dude »

Hello all, I am using php 5.1.2 and when i just

Code: Select all

echo "Time: ". date("h:i:s")."\n";
it does not display the correct time as my system on the localhost, and i have also check this with php4 , it is working fine in php4, please help thanks
User avatar
louie35
Forum Contributor
Posts: 144
Joined: Fri Jan 26, 2007 8:40 am
Location: Dublin
Contact:

Post by louie35 »

try this:

Code: Select all

echo "Date/Time".date("Y-m-d H:i:s");
User avatar
sarav_dude
Forum Newbie
Posts: 24
Joined: Sun Apr 30, 2006 8:40 am
Location: India
Contact:

Post by sarav_dude »

Thanks for considering, i used the code you provided, it displays on localhost :

Date/Time2007-04-26 12:54:15


and my current system time is 6:25 pm, i cant able to figure out , the difference, please help
User avatar
louie35
Forum Contributor
Posts: 144
Joined: Fri Jan 26, 2007 8:40 am
Location: Dublin
Contact:

Post by louie35 »

if is running on localhost then it has to be something else wrong there.
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

If you're using PHP5, post the results of this:

Code: Select all

<?php echo date_default_timezone_get(); ?>
User avatar
sarav_dude
Forum Newbie
Posts: 24
Joined: Sun Apr 30, 2006 8:40 am
Location: India
Contact:

Post by sarav_dude »

Thats what i am trying to figure out, with php 4 it is working fine, i am currently using php5.1.2 , may be some settings in the php.ini file or something ...
User avatar
sarav_dude
Forum Newbie
Posts: 24
Joined: Sun Apr 30, 2006 8:40 am
Location: India
Contact:

Post by sarav_dude »

aaronhall wrote:If you're using PHP5, post the results of this:

Code: Select all

<?php echo date_default_timezone_get(); ?>
it is : UTC
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

And now please try

Code: Select all

echo phpversion(), "<br />\n";
echo php_uname(), "<br />\n";
echo "Time: ", time(), "<br />\n";
echo "Date/Time: ", date("Y-m-d H:i:s T O e");
on both systems, your server and localhost and post the output.
If it shows the dns name of your server and you don't want us to see it remove that part, it's irrelevant.
User avatar
sarav_dude
Forum Newbie
Posts: 24
Joined: Sun Apr 30, 2006 8:40 am
Location: India
Contact:

Post by sarav_dude »

volka wrote:And now please try

Code: Select all

echo phpversion(), "<br />\n";
echo php_uname(), "<br />\n";
echo "Time: ", time(), "<br />\n";
echo "Date/Time: ", date("Y-m-d H:i:s T O e");
on both systems, your server and localhost and post the output.
If it shows the dns name of your server and you don't want us to see it remove that part, it's irrelevant.

on localhost :

Code: Select all

5.1.2
Windows NT SARAV 5.1 build 2600
Time: 1177593063
Date/Time: 2007-04-26 13:11:03 UTC +0000 UTC
on server:

Code: Select all

5.1.6
Linux server (dnsname )ELsmp #1 SMP Fri Oct 6 06:21:39 CDT 2006 i686
Time: 1177593189
Date/Time: 2007-04-26 09:13:09 EDT -0400 America/New_York
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

Try adjusting the date.timezone directive in php.ini (http://www.php.net/manual/en/ref.dateti ... e.timezone)
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Your server has another zoneinfo/timezone setting than localhost.
EDT -0400 America/New_York means, America/New_York currently is UTC -4 hours.
UTC=13:11:03 <-> EDT=09:13:09
When daylight saving is over America/New_York has UTC -5 hours (EST)
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

I think he was asking about a discrepancy between his system time and the time reported by PHP on that same system.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Re: Time not displaying properly with php 5.1.2

Post by volka »

If so I misunderstood
sarav_dude wrote:it does not display the correct time as my system on the localhost
User avatar
sarav_dude
Forum Newbie
Posts: 24
Joined: Sun Apr 30, 2006 8:40 am
Location: India
Contact:

Post by sarav_dude »

aaronhall wrote:I think he was asking about a discrepancy between his system time and the time reported by PHP on that same system.
Yes it is what i am trying to ask , the same thing i have checked on the php4, it shows the correct time, may be there is an bug in the version php5.1.2 for the server timings (the server is on the same system i.e., localhost), any way the solution to the problem is to manually calculate the time-difference and adds them to show the needed time. thanks all
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

I stand corrected.
aaronhall wrote:Try adjusting the date.timezone directive in php.ini (http://www.php.net/manual/en/ref.dateti ... e.timezone)
You should do that instead of fiddeling with the timestamp.

Code: Select all

<?php echo get_cfg_var('cfg_file_path'); ?>
tells you which php.ini you have to change.
Don't forget to restart the webserver after changing the php.ini
Post Reply