Wowpedia

We have moved to Warcraft Wiki. Click here for information and the new URL.

READ MORE

Wowpedia
Advertisement

Returns the current server time in hours and minutes

hours,minutes = GetGameTime();

Parameters

Returns

hours
Number - The current hour (0-23).
minutes
Number - The minutes passed in the current hour (0-59).

Note: This function appears to return the current local time of the physical instance server you are actually playing on, and not that of the world instance server (realm server) you normally go to when you log in. Servers for instances such as for raids and pvp are often shared between login world servers, sort of like the idea of battlegroups. And instance servers are not always running using the same timezone as the login realm server. This is particualry noticable for Oceanic and other low population world servers. See below for more...

Example

local hour,minute = GetGameTime();
message(hour .. ":" .. minute);

Result

A message with the current server time appears.

To use this in a macro:

/script local hour,minute = GetGameTime();DEFAULT_CHAT_FRAME:AddMessage (hour .. ":" .. minute);


More notes:

So for example you log into US Ysera EST at 18:00, and enter Ulduar runing on an instance server that is PST. Suddenly the time returned will be 3 hours behind the time you were getting. Confusing but important :) Please keep this in mind if using this time for anything important functionally, such as diffing times or using as part of functional historical data.

Getting consistant times you have two basic choices. Server time is good because all players in a realm will have the same time within more or less a mintue accuracy. Client time is good because you have second precision, but everyones times are different, as not only do people log into realm servers from other timezones, but you also have no idea how correct their local time is, from unset clocks to bad user tiemzone, and lots of variance. The "instance server not same time as login server" problem suddenly makes the server time much less valuable for consistancy. Two reasons, even if the server is in the same timezone as the login server, you might have variance between the two server like 5-10 mintues, though not typicaly the case. Using local time for most apps where a univeral time isnt important is the way to go.

The third option is to mix the two and run a timer correction update event in the background, where you get a base time difference between local and server time as to correct local time to server time, and base the seconds purely off of local time. The update event basically corrects the base difference over time to keep it acruate with server time. The base correction update is necessary because users computers can drift dramatically depending on the computer, and because users can choose to change their timezone or clock at any time. Also doing time diffs and adds is not as simple as it sounds; its a bit contrived to get it right. With the newer problem (the reason for the note) you will need to basically shut off the base correction when a player enters an instance and save the difference value to your saved vars, in case the player restarts or logs into an instance instead of the realm world server. This leaves the problem of a user installing the addon and loging on to an instance server first rather than the realm world server (and people who raid know that can really happen a lot, ala "oh let me go enable or install that addon i need, brb"). In this case you will need to seed the base with the difference of the instance server just once and then follow the rule of shutting it off in an instance, where it will natuarally be corrected within a minute or so of entering realm world server.

This is alot of trouble. All blizz cound do to fix this would be to make a hole where to continue to get server time from the realm server for addons, and probably not happy thing to change.

Advertisement