WordPress – Stop screwing with the timezone!

So my dates were not displaying correctly and it turns out that WordPress is to blame.

After checking the data and finding that it was correct, I was confused as to why a wordpress page was displaying the wrong date for a correct unix timestamp.

WordPress was screwing with the timezone setting of PHP. This little factoid took a good 30 minutes for my decaffeinated brain to figure out.

So, here is a small function that will help out displaying a date with the correct info:

/**
* Echo's a date with the timezone setting unfuxed
* 
* @param mixed $format
* @param mixed $timestamp
*/
function echo_date($format,$timestamp) {
	$old_tz = date_default_timezone_get();
	date_default_timezone_set(get_option('timezone_string'));
	echo date($format,$timestamp);
	
	date_default_timezone_set($old_tz);
}