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 时候一样

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM