Time Lua UTC时间不一致性
Lua 5.1文件说: 如果格式以“!”开头,然后将日期格式化为协调格式 世界时间 如果格式为Time Lua UTC时间不一致性,time,lua,utc,Time,Lua,Utc,Lua 5.1文件说: 如果格式以“!”开头,然后将日期格式化为协调格式 世界时间 如果格式为%c,
%c
,代码的行为似乎是正确的
local date_1 = os.date("!%c")
local date_2 = os.date("%c")
print("utc date: "..date_1)
print("not utc date: "..date_2)
如果格式为*t
,
的行为似乎被交换了
local time_1 = os.time(os.date("!*t"))
local time_2 = os.time(os.date("*t"))
print("should be utc time, but is not: "..time_1) -- this should be UTC, and is not
print("should not be utc time, but is: "..time_2) -- this should not be UTC, but is
日期通过以下方式进行测试:
这是为什么?操作系统日期(“!*t”)
和操作系统日期(“*t”)返回的表是正确的。我只打印hour
字段。请注意,它们与%c
格式一致:
local date_1 = os.date("!%c")
local date_2 = os.date("%c")
print("utc date: "..date_1)
print("not utc date: "..date_2)
print("utc date hour: " .. os.date("!*t").hour)
print("not utc date hour: " .. os.date("*t").hour)
我的机器上的输出(中国标准时间,UTC+08:00):
但是,os.time
取表,假设是本地时间,并返回历元。因此,本地时间转换为实际历元,但utc时间不是
print(os.time{year=1970, month=1, day=1, hour=8})
在我的机器上输出0
print(os.time{year=1970, month=1, day=1, hour=8})