Tuesday, January 01, 2008

Change timezone for PHP

It's now 2008 and this will be my first post for '08. I hope everyone had a happy New Years day.

I few months back I was building a site using PHP and I wanted to put the time in EST form in a hidden input element for a form I was building, but the web hosting server was located in western US so the time was being displayed in WST form. So I looked around for a way to somehow get the time to display in EST form but I couldn't find a solution then.

A few days ago I found a solution to this problem I was having. So now I able to have the time display in EST form in a hidden input element for my form. I hope this helps others who are having this problem.

PHP Code:

putenv("TZ=US/Eastern");
$time = time ();
print date("l, F jS, Y",$time) . " @ ". date("g:i A")."\n";

I can't take credit for finding the solution I needed, I found it here. If you want to change the time to a different time zone other than the eastern time zone, check the site, they give a list of timezones.

No comments: