Go的time.Format(布局字符串)参考时间的意义是什么?

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?

Source: http://golang.org/pkg/time/#Time.Format

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.

  • Mon is recognized litteraly as monday so this is the week day's name
  • the comma is left untouched
  • 02 is recognized as the integer value 2, representing a day-of-month in the index
  • Jan is the known english abbreviation for the january month, so this is used for the month part
  • 06 is 6 so this the year part
  • 15 is equivalent to 3 and represent the hour
  • the ':' character is left untouched
  • 04 is 4, therefore the minute
  • MST is interpreted litteraly

See http://golang.org/src/time/format.go?s=12714:12756#L117 for the exact algorithm.

In American date format, it's Mon, 1/2 03:04:05 PM 2006 -0700.

1, 2, 3, 4, 5, 6, 7.