Golang time format

An explanation of the special golang time formatting date

The specific string

Golang uses a very specific string for formatting time output, and it is this Mon Jan 2 15:04:05 MST 2006

The reference time is in numerical order but for the -0700 timezone (California is GMT-7 🙄):
Layout = "01/02 03:04:05PM '06 -0700" // The reference time, in numerical order.

Example

To setup your date and time formatting you have to rearrange those exact values.

1
2
current_time.Format("2006-01-02")
current_time.Format("06-02-01 mon 15:04")

The values will then get replaced by the time.Time value for the given variable, i.e. 2006 will become 2022 and so on.

More info here

Built with Hugo
Theme Stack designed by Jimmy