如何使用 yyyyMMddHHmmss 格式格式化当前时间?
技术问答
353 人阅读
|
0 人回复
|
2023-09-12
|
我试着用这种格式格式化当前时间yyyyMMddHHmmss。
- @7 q* `0 `+ M9 I) K5 o6 V( P7 Xt := time.Now()fmt.Println(t.Format("yyyyMMddHHmmss"))
; f# h6 g. [; J3 u' _ 即输出:
y. Y5 N# x& B8 syyyyMMddHHmmss
8 k3 e+ y+ |0 D: F c 有什么建议?
T1 W& ]/ g& y2 _, V
: ]& O0 a! Q( S0 N9 ] 解决方案:
( s0 z0 ~! x8 |6 E" j J8 V, P 用
7 g& ~; t/ }) i7 l. Pfmt.Println(t.Format("20060102150405")) Z: V. Y: R [
由于 Go 使用以下常量格式化日期,请参阅此处
* F* ]# K1 H( M2 m3 B6 _, Iconst stdLongMonth = "January" stdMonth = "Jan" stdNumMonth = "1" stdZeroMonth = "01" stdLongWeekDay = "Monday" stdWeekDay = "Mon" stdDay = "2" stdUnderDay = "_2" stdZeroDay = "02" stdHour = "15" stdHour1212 = "3" stdZeroHour12 = "03" stdMinute = "4" stdZeroMinute = "04" stdSecond = "5" stdZeroSecond = "05" stdLongYear = "2006" stdYear = "06" stdPM = "M" 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)1 Z- [7 \, [6 r
|
|
|
|
|
|