夏令时 - 在无夏令时的时区,isdst参数会被os.time忽略

测试代码

local date1 = { year = 2024, month = 11, day = 3, hour = 1, min = 0, sec = 0 }
local timestamp1 = os.time(date1)

local date2 = { year = 2024, month = 11, day = 3, hour = 2, min = 0, sec = 0, isdst = true }
local timestamp2 = os.time(date2)

local delta = timestamp1 - timestamp2
if 0 == delta then
    print("equals", timestamp1)
else
    print("delta", delta, timestamp1, timestamp2)
end

 

1) 在有夏令时的时区(UTC-5),结果一样

image

对应:2024-11-03 01:00:00(EST,UTC-5)

 

2) 在无夏令时的时区(UTC+8),结果不一样

image

date1对应:2024-11-03 01:00:00(UTC+8)

date2对应:2024-11-03 02:00:00(UTC+8)

 

posted @ 2025-08-30 15:31  yanghui01  阅读(3)  评论(0)    收藏  举报