go 时间和日期 格式化

 

    t:=time.Now()

    fmt.Println(time.Now())
    fmt.Printf("%4d %02d %02d\n",t.Year(),t.Month(),t.Day())
    fmt.Printf("%02d.%02d.%4d\n", t.Day(), t.Month(), t.Year())

    t = time.Now().UTC()
    fmt.Println(t)

    fmt.Println(t.Format(time.RFC822)) // 21 Dec 11 0852 UTC
    fmt.Println(t.Format(time.ANSIC)) // Wed Dec 21 08:56:34 2011
    fmt.Println(t.Format("02 Jan 2006 15:04")) // 21 Dec 2011 08:52
    s := t.Format("20060102")
    fmt.Println(t, "=>", s)

    s = t.Format("20060102 15:04:05")
    fmt.Println(t, "=>", s)

输出:

2020-05-21 10:57:26.208685 +0800 CST m=+0.000072362
2020 05 21
21.05.2020
2020-05-21 02:57:26.20884 +0000 UTC
21 May 20 02:57 UTC
Thu May 21 02:57:26 2020
21 May 2020 02:57
2020-05-21 02:57:26.20884 +0000 UTC => 20200521
2020-05-21 02:57:26.20884 +0000 UTC => 20200521 02:57:26

 

展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客
应支付0元
点击重新获取
扫码支付

支付成功即可阅读