Forum Moderators: coopster

Message Too Old, No Replies

Timestamp display incorrect time

         

opiston

7:03 pm on Aug 28, 2005 (gmt 0)

10+ Year Member



Hi all,
This is the code that I use to display the current time.

<?php
$timestamp = time();
$date_now = date('m/d/y g:i a', $timestamp);
print $date_now;
?>

It is 12:03pm at where I live (USA West)
But for some reason the above code gives me 08/28/05 4:03 am
Is there a way to specify the time for US West?

Regards
Opiston

dreamcatcher

8:23 pm on Aug 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi opiston,

You can use the strtotime function if you want to adjust the time.

ie:

$date_now = date('m/d/y g:i a', strtotime('+5 hours));

Not sure what the time difference is. Replace +5 with whatever you need. Or use - if you want.

dc

opiston

9:48 pm on Aug 28, 2005 (gmt 0)

10+ Year Member



Hi dreamcatcher,
Thanks for your help.
I added 8 more hours and got a correct time.

Best Regards
Opiston

dcrombie

3:21 pm on Aug 29, 2005 (gmt 0)



Talk about re-inventing the wheel ;)

Just add something like this to your script before calling the date function:

putenv("TZ=America/New_York");