golang utc时间转本地时间

前端之家收集整理的这篇文章主要介绍了golang utc时间转本地时间前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

代码如下

now := time.Now()
year,mon,day := now.UTC().Date()
hour,min,sec := now.UTC().Clock()
zone,_ := now.UTC().Zone()
fmt.Printf("UTC 时间是 %d-%d-%d %02d:%02d:%02d %s\n",year,day,hour,sec,zone)

year,day = now.Date()
hour,sec = now.Clock()
zone,_ = now.Zone()
fmt.Printf("本地时间是 %d-%d-%d %02d:%02d:%02d %s\n",zone)

字符串转time.Time

Bdate := "2014-06-24 14:30"//时间字符串

t,err := time.ParseInLocation("2006-01-02 15:04",Bdate,time.Local)//t被转为本地时间的time.Time

t,err := time.Parse("2006-01-02 15:04",Bdate)//t被转为UTC时间的time.Time

utf转本地时间

t,_ := time.Parse(time.RFC3339,"2016-08-22T08:23:42Z")
fmt.Println(t.In(time.Local))
原文链接:https://www.f2er.com/go/190955.html

猜你在找的Go相关文章