如下所示

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

 

相关文章:

  • 2020-12-27
  • 2021-05-09
  • 2022-03-10
  • 2022-01-18
  • 2022-12-23
  • 2021-05-31
  • 2021-11-14
猜你喜欢
  • 2021-09-22
  • 2021-09-18
  • 2021-11-23
相关资源
相似解决方案