API time
Jump to navigation
Jump to 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
, andday
, and may have fieldshour
,min
,sec
, andisdst
. For a description of these fields, see the Lua reference manual.
Returns
- timestamp
- number - Time in seconds since the epoch. If applicable, the time for
dateTable
.
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. 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
- GetTime()
External links
- GitHub FrameXML, Gethe
- Globe "wut?" Tool, Townlong-Yak