How to format hour in 24h format without leading 0 ?

66 views
Skip to first unread message

christoph...@gmail.com

unread,
Apr 25, 2022, 12:10:45 PM4/25/22
to golang-nuts
I need to format a time stamp hours in 24h format but without leading 0. This means 7 -> "7" and 17 -> "17".

For 24h values, the only formatting key value provided and documented is 15. But this produces "7" -> "07" and 17 -> "17" which is not what I need.

According to  https://gosamples.dev/date-time-format-cheatsheet/, a formatting key word for this format seam to be missing.

Note by the way that the formatting key value numbering is easy to remember for Americans only. Every time I need to format a time value I have to look it up with google, or the cheat sheet referenced above.

Tamás Gulácsi

unread,
Apr 25, 2022, 12:23:10 PM4/25/22
to golang-nuts
strings.Replace(t.Format(time.RFC3339), "T0", "T", 1)
?
Reply all
Reply to author
Forward
0 new messages