-
-
Save xiangyuan/e7b26554939b1796c903975eac9b1846 to your computer and use it in GitHub Desktop.
lua中获取本地时区(timezone)的方法
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
打印时区信息 | |
--]] | |
function os.printTimezone() | |
local t = os.time() | |
local ut = os.date('!*t',t) | |
local lt = os.date('*t',t) | |
local tzdt = (lt.hour - ut.hour) * 3600 + (lt.min - ut.min) * 60 | |
print(string.format("本地时间与标准时间差 %d(%.1f小时) 分钟", tzdt, tzdt / 3600)) | |
end | |
--[[ | |
返回当前的系统时区(单位:秒) | |
--]] | |
function os.timezone() | |
local now = os.time() | |
return os.difftime(now, os.time(os.date("!*t", now))) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment