Index: GlobalFunctions.php
===================================================================
--- GlobalFunctions.php	(revision 17237)
+++ GlobalFunctions.php	(working copy)
@@ -81,6 +81,17 @@
 	}
 }
 
+# Exists in PHP 5.1.0+
+if( !function_exists( 'date_default_timezone_get' ) ) {
+	function date_default_timezone_get() {
+		return getenv( 'TZ' );
+	}
+}
+if( !function_exists( 'date_default_timezone_set' ) ) {
+	function date_default_timezone_set( $setting ) {
+		return @putenv( 'TZ=' . $setting );
+	}
+}
 
 /**
  * Wrapper for clone(), for compatibility with PHP4-friendly extensions.
Index: Parser.php
===================================================================
--- Parser.php	(revision 17237)
+++ Parser.php	(working copy)
@@ -2351,8 +2351,8 @@
 		# Use the time zone
 		global $wgLocaltimezone;
 		if ( isset( $wgLocaltimezone ) ) {
-			$oldtz = getenv( 'TZ' );
-			putenv( 'TZ='.$wgLocaltimezone );
+			$oldtz = date_default_timezone_get();
+			date_default_timezone_set( $wgLocaltimezone );
 		}
 		$localTimestamp = date( 'YmdHis', $ts );
 		$localMonth = date( 'm', $ts );
@@ -2364,7 +2364,7 @@
 		$localYear = date( 'Y', $ts );
 		$localHour = date( 'H', $ts );
 		if ( isset( $wgLocaltimezone ) ) {
-			putenv( 'TZ='.$oldtz );
+			date_default_timezone_set( $oldtz );
 		}
 
 		switch ( $index ) {
@@ -3626,13 +3626,13 @@
 		 * than the one selected in each user's preferences.
 		 */
 		if ( isset( $wgLocaltimezone ) ) {
-			$oldtz = getenv( 'TZ' );
-			putenv( 'TZ='.$wgLocaltimezone );
+			$oldtz = date_default_timezone_get();
+			date_default_timezone_set( $wgLocaltimezone );
 		}
 		$d = $wgContLang->timeanddate( date( 'YmdHis' ), false, false) .
 		  ' (' . date( 'T' ) . ')';
 		if ( isset( $wgLocaltimezone ) ) {
-			putenv( 'TZ='.$oldtz );
+			date_default_timezone_set( $oldtz );
 		}
 
 		# Variable replacement
