gpt4 book ai didi

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

转载 作者:IT老高 更新时间:2023-10-28 12:57:27 28 4
gpt4 key购买 nike

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

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

即输出:

yyyyMMddHHmmss

有什么建议吗?

最佳答案

使用

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

由于 Go 使用以下常量来格式化日期,请参阅 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
)

关于time - 如何使用 yyyyMMddHHmmss 格式格式化当前时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20234104/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com