---恢复内容开始---
golang 自定义时区
a1 := time.Now() fmt.Println("a1:", a1) a2 := a1.Format("2006-01-02 15:04:05") fmt.Println("a2:", a2) a3, _ := time.Parse("2006-01-02 15:04:05", a2) fmt.Println("a3:", a3) a4 := time.Now() fmt.Println("a4:", a4) a5 := a4.UTC() fmt.Println("a5:", a5) secondsEastOfUTC := int((8 * time.Hour).Seconds())
//上面是计算8小时一共多少秒,下面是定义a6这个变量为自定义的时间格式,下面用的时间格式名叫"CST" ,这个格式我们定义为utc时间+8小时 a6 := time.FixedZone("CST", secondsEastOfUTC) a7 := a5.In(a6) fmt.Println(a7) fmt.Println("a5.Sub(a3):", a5.Sub(a3)) fmt.Println("a4.Sub(a1):", a4.Sub(a1))
原文:https://www.cnblogs.com/xiaopingfeng/p/9998649.html