Skip to content

Instantly share code, notes, and snippets.

@xiangyuan
Forked from 1901/timezone.lua
Created August 23, 2017 02:40
Show Gist options
  • Save xiangyuan/e7b26554939b1796c903975eac9b1846 to your computer and use it in GitHub Desktop.
Save xiangyuan/e7b26554939b1796c903975eac9b1846 to your computer and use it in GitHub Desktop.
lua中获取本地时区(timezone)的方法
--[[
打印时区信息
--]]
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