API time

From Wowpedia
Jump to: navigation, search

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

timestamp = time([dateTable])

Arguments

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.

Returns

timestamp 
number - The time for dateTable, otherwise time in seconds since the epoch.

Details

  • 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.

Example

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

Comparison

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.

-- unix time
time()                             -- 1596157547
GetServerTime())                   -- 1596157549
C_DateAndTime.GetServerTimeLocal() -- 1596139440 unix time offset by UTC (e.g. minus 5 hours)
-- local time
date()                             --  "Fri Jul 31 03:05:47 2020"
-- realm time
GetGameTime()                          -- 20, 4
C_DateAndTime.GetCurrentCalendarTime() -- hour:20, minute:4

See also

External links