Manual talk:Timezone

Background
This article was inspired by a recent install of MediaWiki and an unsuccessful attempt to set the global Timezone to something other than UTC. After finding several broken, incomplete and incorrect pages it became apparent that a Help:Timezone page was badly needed.

The primary working method was taken from a previous article and from this wikitech email authored by Brion Vibber.

It was tested on a system with the following Versions: * MediaWiki: 1.5.6 * PHP: 4.3.11 (apache) * MySQL: 4.1.13-standard

The unconfirmed methods were tested unsuccessfully on the same system but included for further testing. Locker 09:55, 2 March 2006 (UTC)

I tried these on MediaWiki: 1.6.7, PHP: 4.3.5 (cgi), MySQL: 4.1.11-Debian_4sarge2-log, CEST time zone. By default, both logs and signatures show UTC. --Tgr 07:21, 20 July 2006 (UTC)
 * Using the primary method (with "Europe/Budapest") does absolutely nothing (except for changing the "(UTC)" text in the signature).
 * Adding Date("I") as suggested does nothing either.
 * Using only the $wgLocalTZoffset = date("Z") / 3600; line and nothing else leaves server time unchanged, and sets local time to server time +2. This gives correct CEST time in recentchanges and logs (including the deletion log; I dind't test the upload log), but still UTC in signatures.

My host probably didn't support the tz database. Primary method works fine, but I had to support time zone and DST manually. Rules for that can be found here. --Tgr 08:54, 20 July 2006 (UTC)

Just two lines are required in LocalSettings.php
Using these two lines only (for e.g. New Zealand Date Time) works a treat $wgLocaltimezone = "Pacific/Auckland"; $wgLocalTZoffset = date("Z") / 60; It fixes the incorrect displaying of Extension:RSS, along with all history pages (e.g. upload, deletion, recent pages logs).

--131.203.252.214 00:30, 6 July 2010 (UTC)

Use localtime
I'm using MediaWiki 1.6.6. I have tried the method mentioned in Help:Timezone and the time displayed successfully in history and recentchanges. The signature is not affected, but it always shows the correct time, regardless I change the $wgLocaltimezone or not. How is the mechanism in MediaWiki so that there are two different time functions? How to fix this? It is very critical because whenever I use the magic word, it points to the wrong time. TIA --Semut 13:18, 1 June 2006 (UTC)
 * always shows UTC time. Use instead. See: http://en.wikipedia.org/wiki/Help:Variable#Varying_with_time -- Mårten 193.200.150.167 18:28, 26 October 2008 (UTC)

Server May Crash..!! 
It works, but the server may crash.

My environment:


 * Windows XP sp2
 * AppServ 2.5.6
 * Apache: 2.2
 * PHP: 5.1.4 (apache2handler)
 * MySQL: 5.0.22-community-nt-log)
 * MediaWiki: 1.8.0

--Chlon 03:55, 16 October 2006 (UTC)

Really!
I confirm the existence of that problem. When I tried that primary method I got error: "An unhandled win32 exception occured in Apache.exe [2320]." My environment:


 * Windows XP sp1
 * Apache: 2.0.59 (Win32)
 * PHP: 5.2.0
 * MySQL: 5.0.27-community-nt
 * MediaWiki: 1.8.2

Experimentally I found out, that probably the line  is causing problem. CodeMonk 00:03, 28 November 2006 (UTC)

Confirmed
I can also confirm site failure (PHP has encountered an Access Violation at 7C81BD02) when this directive is set.


 * OS: Windows Server 2003 SP2
 * Web: Internet Information Services 6
 * PHP: 5.2.1
 * MySQL: 5.0.37-community-nt
 * MediaWiki: 1.10.1

IIS and MySQL must be restarted to clear this error.

Does not work on my MediaWiki 1.10.0 upgrade!
Used the code to no avail. It does not work since I upgraded from 1.6.10. $wgLocaltimezone = "Asia/Jerusalem"; $oldtz = getenv("TZ"); putenv("TZ=$wgLocaltimezone"); $wgLocalTZoffset = date("Z") / 3600; putenv("TZ=$oldtz");
 * 1) Versions before 1.7.0 used $wgLocalTZoffset as hours.
 * 2) After 1.7.0 offset as minutes

date_default_timezone_set("Asia/Jerusalem"); I'm lost now. Nate, 89.1.57.35 23:51, 6 June 2007 (UTC)


 * Signatures on talk pages will show correct time, Special:Recentchanges shows the same edit using wrong time! Nate, 89.1.57.35 00:08, 7 June 2007 (UTC)


 * I don't know what happened, but as I was playing with editing it, putting stuff on an off again, suddenly this agreed to work.

$wgLocaltimezone = "Asia/Jerusalem"; $oldtz = getenv("TZ"); putenv("TZ=$wgLocaltimezone"); $wgLocalTZoffset = date("Z") / 60; putenv("TZ=$oldtz");
 * 1) Versions before 1.7.0 used $wgLocalTZoffset as hours.
 * 2) After 1.7.0 offset as minutes
 * Date("Z") returns seconds, previous division by 3600 was giving hours, but as the specification says we are now to use minutes - division by 60. Funny thing is I already tried it before. Don't know why this time it caught on. Very weird. Nate, 89.1.57.35 02:06, 7 June 2007 (UTC)

Seriously?
Is there really a 5 line php-patch necessary to display the time normally? Isn't there a Special:Timezone page yet, where i can tell the wiki to use the servertime?

Server time != mediaWiki-time
Hi there, my server seems to be in the correct time, correct time zone and tht php.ini is adjusted as well to my timezone. The mediaWiki on the server however displays in the preferences, that the server is minus two hours of what it shows. How can this be? I am in Europe/Berlin timezone. --Thekryz 16:50, 24 May 2008 (UTC)
 * It seems that the server time that the MediaWiki displays, always is the UTC time. -- Mårten 193.200.150.167 18:53, 26 October 2008 (UTC)
 * Same for me. Here are some strings from my LocalSettings.php, try to guess why I commented all of them out:

//$wgLocaltimeZone="Europe/Moscow"; /*oldtz = getenv("TZ"); putenv("TZ=$wgLocaltimezone"); $wgLocalTZoffset = date("Z") / 60; putenv("TZ=$oldtz");*/ //$wgDefaultUserOptions['timecorrection'] = '05:00'; //$wgLocaltimezone = "UTC+3,M3.4.0/2,M10.4.0/3"; //last sunday march 2:00+1, last sunday oct 3:00-1 //$wgLocalTZoffset = date("Z") / 60; //$wgLocaltimezone="UTC+3"; //$wgLocaltimeZone=":Europe/Moscow";
 * Neither works, MW is still in UTC. What else can I try? Help me please. MW 1.13.2, PHP 5.2.9, Windows 2003 Server.

Daylight saving time
Hi there, I tried every method described in this manual to make my MediaWiki 1.8.2 on Windows XP SP2 take daylight saving time into account, but didn't succeed. The problem was not in wrong server timezone, PHP date function returned correct time. The fact is that MediaWiki uses UTC time internally, and every user has his own time shift. So if user's local time is re-adjusted because of daylight saving time, every user must manually re-adjust that shift in individual settings. That's a correct way, but it can't be done automatically. The wrong way will be to adjust user's time shift during daylight saving time automatically, though daylight saving is not used in many countries. In that case adjusting $wgLocalTZoffset variable won't help (and there is also a bug in userAdjust function in Language.php in my 1.8.2), so this must be done in Language.php file:

} else { $hrDiff = intval( $tz ); } $hrDiff += date("I"); if ( 0 == $hrDiff && 0 == $minDiff ) { return $ts; }
 * 1) No difference ? Return time unchanged

Just add the bold line in that code fragment. After that, user's time shift will be silently re-adjusted during daylight saving time, as it is set on the server. I guess, this will work not only in 1.8.2. Best regards, CodeMonk 02:30, 18 June 2008 (UTC)

DST on server in your own timezone
If you have your MediaWiki on a server in your own timezone, nothing mentioned in this article, but the following line in LocalSettings.php was needed for me to get the correct time, including correct behaviour during DST shifts (daylight saving time): $wgLocalTZoffset = date("Z") / 60; Then you don't have to use $wgLocaltimezone to get correct times on signatures, since MediaWiki uses the server's time by default if $wgLocaltimezone is not defined, and the server normally knows when to go on/off DST. However $wgLocalTZoffset has to be used as above to get correct times on edits, since the default value on $wgLocalTZoffset is UTC time. Since date("Z") picks the time from the server, again DST is taken care of duly. -- Mårten 193.200.150.167 18:53, 26 October 2008 (UTC)

OMG
Holy cow, I have to read a book on how to change timezone. common. true:S

Symbolic time zone names
According to this (and my experience :-)), symbolic time zone names like "Europe/Berlin" have to be preceded by a ":" when used as a TZ setting, i. e. ":Europe/Berlin". Many libraries accept the variant without the colon as well, but I prefer playing it safe :-). --Tim Landscheidt 12:12, 6 April 2009 (UTC)