What is the significance of Go's time.Format(layout string) reference time, ie:
Mon Jan 2 15:04:05 -0700 MST 2006
This specific time couldn't have been chosen completely randomly, right?
What is the significance of Go's time.Format(layout string) reference time, ie:
Mon Jan 2 15:04:05 -0700 MST 2006
This specific time couldn't have been chosen completely randomly, right?
Each part of the date is used as an index:
Jan -> 1 -> Month
2 -> 2 -> Day-of-Month
15 = 3PM -> 15/3 -> hour
04 -> 4 -> minute
05 -> 5 -> second
2006 -> 6 -> year
-0700 -> 7 -> time-zone
So according to the doc:
Since MST is GMT-0700, the reference time can be thought of as 01/02 03:04:05PM '06 -0700
This makes it easy for the time.Format
method to parse human-readable date format specifications that are visually identical to the desired result.
Compare this to for example the strftime
C function that uses hard-to-remember format strings such as "%a, %d %b %y %T %z"
which represents a RFC 822-compliant date format.
The Go equivalent is: "Mon, 02 Jan 06 15:04 MST"
.
The time.Format
will tokenize this string and analyze each word.
':'
character is left untouchedSee http://golang.org/src/time/format.go?s=12714:12756#L117 for the exact algorithm.