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?

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. :)

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"

Member Avatar for diafol

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

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');

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.

Thanks.

I got it working now.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.