Golang的time包的Local到底是干嘛的
如下所示
package main import ( "fmt" "time" ) func main() { for { location, err := time.LoadLocation("Asia/Shanghai")//"America/New_York" if err == nil { time.Local = location } fmt.Println(time.Now().UTC().Format("2006-01-02 15:04:05"))//输出英国伦敦时区时间 - 0时区 - UTC±0 fmt.Println(time.Now().Local().Format("2006-01-02 15:04:05"))//输出中国上海时区 - 中国时间 fmt.Println(time.Now().Format("2006-01-02 15:04:05"))//输出中国上海时区 - 中国时间 } }
似乎 Local 不管再time有无设置时区,输出都没没加上 local 时候一样
time.Local *Location
有一个 time.initLocal 函数清楚地显示
如果未显式指定时区,则默认使用系统时区。在 Linux/MacOS 上,默认使用的是 /etc/localtime 指向的时区数据
I can see a bigger world.