加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

golang utc时间转本地时间

发布时间:2020-12-16 18:53:14 所属栏目:大数据 来源:网络整理
导读:代码如下 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 %sn",year,day,hour,sec,zone)year,day = now.Date()hour,sec = now.Clock()zon

代码如下

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 %sn",year,day,hour,sec,zone)

year,day = now.Date()
hour,sec = now.Clock()
zone,_ = now.Zone()
fmt.Printf("本地时间是 %d-%d-%d %02d:%02d:%02d %sn",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))

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读