时区(time-zone)常见问题总结

1 概念

https://archlake.net/zh/time-zone-concept.html

2 经纬度换时区

给定经纬度得出时区名称具体时区UTC偏移量

2.1 经纬度时区ID的转换

如:

(42.7235, -73.6931) —-> America/New_York [Location Name]

http://efele.net/maps/tz/ (不再维护),https://github.com/evansiroky/timezone-boundary-builder 提供经纬度时区ID的转换数据(由于不同国家政治策略的变动,这个数据经常更新)

各语言的库 https://github.com/evansiroky/timezone-boundary-builder#lookup-libraries

2.2 时区ID具体夏令时偏移量的转换

如:

America/New_York + 2016年12月26日 –> UTC - 5:00

America/New_York + 2016年10月26日 –> UTC - 4:00

http://www.iana.org/time-zones 提供时区ID具体夏令时偏移量的转换数据(由于不同国家政治策略的变动,这个数据经常更新)(有golang标准库)

https://www.iana.org/time-zones/repository/tz-link.html

https://www.iana.org/time-zones/repository/releases/tzdb-2017b.tar.lz

https://github.com/eggert/tz

https://golang.org/pkg/time/#LoadLocation

https://github.com/golang/go/tree/release-branch.go1.4/lib/time (golang标准库)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package main

import (
"fmt"
"time"

"github.com/bradfitz/latlong"
)

func main() {
location, _ := time.LoadLocation(latlong.LookupZoneName(42.7235, -73.6931))
zone, offset := time.Now().In(location).Zone()

fmt.Print(zone, "\n")
fmt.Print(offset / 3600)
}

//std out
//EDT
//-4