0

I have almost no experience with PHP so I need some help with a small code block.

My website used to be hosted by a company within my own time zone, so I used the following code to output the date and time on my web page:

<?php
print strftime('%A, %B %d, %Y   %I:%M:%S %P');
print "  Pacific Time";
?>

However, I am in the process of changing to a hosting company that is in a different time zone, three hours ahead of me actually.

How do I change the time displayed on my website so that it is three hours behind the time taken from the server?

3
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by DavidB
0

Well, the answer I have didn't work for me but it's how you are supposed to do it.

At the beginning of your file you need to set the default timezone.

date_default_timezone_set ("Eastern/New_York");

Or you could

echo date("l, F d, Y  h:i:s P",time()+(3*3600));

If I got some of that wrong I apologize in advance. :)

Edited by dietdew12z: n/a

0

Well, the answer I have didn't work for me but it's how you are supposed to do it.

At the beginning of your file you need to set the default timezone.

date_default_timezone_set ("Eastern/New_York");

Oops, it should be "America/New_York"

0

Manually going 3 hours+ isn't a good idea, as some countries have daylight saving, e.g. Summer Time. Better to set the timezone.

0

Thanks for the replies.

Let's assume I use the timezone_set option.
I am on the West Coast; the server is on the East Coast.

So would I simply insert the timezone code

date_default_timezone_set ("America/Tijuana");

and then my existing code?

print strftime('%A, %B %d, %Y   %I:%M:%S %P');
0

Yes, once you set the timezone your code should work the way it is, just set to a different time.

When I did a quick test(which worked this time), I put it right after the session_start(); command but I think as long as it's near the top you should be okay.

Edited by dietdew12z: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.