如何使用 yyyyMMddHHmmss 格式格式化当前时间? [英] How to format current time using a yyyyMMddHHmmss format?

查看:75
本文介绍了如何使用 yyyyMMddHHmmss 格式格式化当前时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to format the current time using this format yyyyMMddHHmmss.

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

即输出:

yyyyMMddHHmmss

有什么建议吗?

推荐答案

使用

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

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

as Go uses following constants to format date,refer here

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
    stdFracSecond0    = ".0", ".00" // trailing zeros included
    stdFracSecond9    = ".9", ".99" // trailing zeros omitted
)

这篇关于如何使用 yyyyMMddHHmmss 格式格式化当前时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆