galjonsfigur 6926c66b16 Polish Lua examples (#2846) | 4 年之前 | |
---|---|---|
.. | ||
README.md | 5 年之前 | |
alaska.zone | 7 年之前 | |
central.zone | 7 年之前 | |
eastern.zone | 7 年之前 | |
mountain.zone | 7 年之前 | |
pacific.zone | 7 年之前 | |
tz.lua | 4 年之前 |
This is a simple module that parses timezone files as found on unix systems. It is oriented around converting the current time. It can convert other times, but it is rather less efficient as it maintains only a single cached entry in memory.
On my linux system, these files can be found in /usr/share/zoneinfo
.
This sets the timezone to be used in subsequent conversions
tz.setzone(timezone)
timezone
this is the timezone string. It must correspond to a file in the file system which is named timezone.zone.true if the zone exists in the file system.
This gets the offset (in seconds) of the time passed as the argument.
tz.getoffset(time)
time
the number of seconds since the epoch. This is the same value as used by the sntp
module.tz = require('tz')
tz.setzone('eastern')
sntp.sync(nil, function(now)
local tm = rtctime.epoch2cal(now + tz.getoffset(now))
print(string.format("%04d/%02d/%02d %02d:%02d:%02d", tm["year"], tm["mon"], tm["day"], tm["hour"], tm["min"], tm["sec"]))
end)
This returns a list of the available timezones in the file system.
tz.getzones()
A list of timezones.