API time

From Warcraft Wiki
Jump to navigation Jump to search

Returns a timestamp for the specified time or the current Unix time.

timestamp = time([dateTable])


table? - Table specifying a date/time to return the timestamp of; if omitted, a timestamp for the current time (per the local clock) will be returned. This table must have fields year, month, and day, and may have fields hour, min, sec, and isdst. For a description of these fields, see the Lua reference manual.


number - Time in seconds since the epoch. If applicable, the time for dateTable.


  • This function is Lua's standard os.time(), shifted into the global namespace.
  • If not given any arguments, time() will return a value based on the local clock, so it is not synchronized among clients. Consider using GetServerTime() instead if you would rather have a value based on the server clock, which IS synchronized among clients.


Prints the current Unix time from the local machine's clock.

/dump time() -- 1118722038

Prints the Unix timestamp for a specific date.

local dateTbl = {
	year = 2004,
	month = 11,
	day = 23,

print(time(dateTbl)) -- 1101207600


When in a EU time zone CEST (UTC+2) and playing on Moon Guard US, CDT (UTC-5). The examples were taken at the same time. Note that time() and date() are tied to your system's clock which can be manually changed.

-- unix time
time()                             -- 1596157547
GetServerTime())                   -- 1596157549

-- local time, same as `date(nil, time())`
date()                             -- "Fri Jul 31 03:05:47 2020"

-- realm time
GetGameTime()                          -- 20, 4
C_DateAndTime.GetCurrentCalendarTime() -- hour:20, minute:4
C_DateAndTime.GetServerTimeLocal()     -- 1596139440 unix time offset by the server's time zone (e.g. UTC minus 5 hours)

See also

External links