夏令时优化
This commit is contained in:
parent
c7a5363a75
commit
534d00a975
@ -30,8 +30,16 @@ func MonthZeroTimestamp() int64 {
|
||||
|
||||
func NextZeroTimestampDuration() int64 {
|
||||
now := time.Now()
|
||||
midnight := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
|
||||
return midnight.AddDate(0, 0, 1).Unix() - now.Unix()
|
||||
location := now.Location()
|
||||
midnight := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, location)
|
||||
nextMidnight := midnight.AddDate(0, 0, 1)
|
||||
|
||||
// Adjust for daylight saving time transitions
|
||||
_, nowOffset := now.Zone()
|
||||
_, nextMidnightOffset := nextMidnight.Zone()
|
||||
offsetDifference := nextMidnightOffset - nowOffset
|
||||
|
||||
return nextMidnight.Unix() - now.Unix() + int64(offsetDifference)
|
||||
}
|
||||
|
||||
// 获取距离下个中午十二点时间戳的秒数
|
||||
|
||||
Loading…
Reference in New Issue
Block a user