【发布时间】:2012-12-09 11:02:24
【问题描述】:
如何从 linux 时间戳中获取当前时间?我可以得到年、月、日、分和秒,但不能得到小时。有什么帮助吗?
当前代码:
local secondsPassed = os ~= nil and os.time() or tick()
local year = 1970 + math.floor(secondsPassed / (86400 * 365.25))
local days = math.floor((secondsPassed % (365.25 * 86400)) / 86400)
days = days + (year - 2011)
local minutes = math.floor((secondsPassed % 3600) / 60)
local seconds = math.floor(secondsPassed % 60)
破碎:
local hours = math.floor((secondsPassed % 86400) / 3600)-- +1
【问题讨论】:
-
如果你的日子是正确的,那么你的小时/分钟/秒怎么能被打破,因为它们都依赖于 secondsPassed?
-
唯一损坏的是几个小时