小编典典

如何使用yyyyMMddHHmmss格式格式化当前时间?

go

我正在尝试使用这种格式来格式化当前时间yyyyMMddHHmmss

t := time.Now()
fmt.Println(t.Format("yyyyMMddHHmmss"))

输出:

yyyyMMddHHmmss

有什么建议?


阅读 1458

收藏
2020-07-02

共1个答案

小编典典

fmt.Println(t.Format("20060102150405"))

由于Go使用以下常量来格式化日期,请参阅此处

const (
    stdLongMonth      = "January"
    stdMonth          = "Jan"
    stdNumMonth       = "1"
    stdZeroMonth      = "01"
    stdLongWeekDay    = "Monday"
    stdWeekDay        = "Mon"
    stdDay            = "2"
    stdUnderDay       = "_2"
    stdZeroDay        = "02"
    stdHour           = "15"
    stdHour12         = "3"
    stdZeroHour12     = "03"
    stdMinute         = "4"
    stdZeroMinute     = "04"
    stdSecond         = "5"
    stdZeroSecond     = "05"
    stdLongYear       = "2006"
    stdYear           = "06"
    stdPM             = "PM"
    stdpm             = "pm"
    stdTZ             = "MST"
    stdISO8601TZ      = "Z0700"  // prints Z for UTC
    stdISO8601ColonTZ = "Z07:00" // prints Z for UTC
    stdNumTZ          = "-0700"  // always numeric
    stdNumShortTZ     = "-07"    // always numeric
    stdNumColonTZ     = "-07:00" // always numeric
)
2020-07-02