Skip to main content

Get Network Time (sys.net_time)

Declaration

sec_ts = sys.net_time([ timeout ])

Parameters

  • timeout
    Number. Optional. Max wait time for networking in seconds. Default: 2.

Returns

  • sec_ts
    Integer. Second-level UNIX timestamp of current network time. Returns 0 on timeout or failure.

Description

This method may yield; other threads may run before it returns.

Examples

local nt = sys.net_time() -- default 2s timeout, returns 0 on timeout
--
local nt = sys.net_time(5) -- 5s timeout
if nt==0 then
sys.alert('Failed to get network time')
else
sys.alert(os.date('Network time\n%Y-%m-%d %H:%M:%S', nt))
end

Note: uses os.date formatting.