处理日期时间 |
|
os.time()
来添加或减去任何时间单位的任何数量(例如 10000 分钟或 -3 个月),而无需将其转换为秒。更棒的是,它还处理夏令时。
os.date()
和 os.time()
的此功能未在 www.lua.org [1] 上记录,导致 Stackoverflow[2] 上出现大量问题。
-- no surprise here: os.date("%c", os.time{year = 2017, month = 01, day = 01, hour = 0, min = 0, sec = 0}) >> "Sun Jan 1 00:00:00 2017" -- and the undocumented feature: os.date("%c", os.time{year = 2017, month = 01, day = 01, hour = 0, min = 20000, sec = 0}) >> "Sat Jan 14 21:20:00 2017" -- also works with negative numbers: os.date("%c", os.time{year = 2017, month = 01, day = -20, hour = 0, min = 0, sec = 0}) >> "Sun Dec 11 00:00:00 2016"