12
$\begingroup$

Go's time formatting strings are uniquely idiosyncratic, and I have not seen any other language use this sort of system:

  • It is based on the exact timestamp for 01/02 03:04:05PM '06 -0700, which is "January 2, 15:04:05, 2006, in time zone seven hours west of GMT" (source).
  • Time formatting strings are the above timestamp formatted into the desired format, e.g. the default datetime format used by the Unix date command can be represented as Mon Jan _2 15:04:05 MST 2006.
  • The documentation for the time package notes that it is a "regrettable historic error" that months come before the days, as in American date formatting.

Where did this sort of datetime formatting come from, i.e. was this taken from another language? And why was this method in particular chosen for Go?

$\endgroup$
10
  • 4
    $\begingroup$ "It is a regrettable historic error that the date uses the American convention of putting the numerical month before the day." I'm guessing it is from "American convention", i.e. the developer picked an arbitrary format that they thought is conventional. $\endgroup$
    – user23013
    Commented Mar 4 at 5:39
  • 2
    $\begingroup$ @user23013 Although separating the year like that is not common. We usually write MM/DD/YY. Seems like they deliberately chose this format to be weird, maybe even to emphasize how broken the American style can be. $\endgroup$
    – Barmar
    Commented Mar 4 at 21:04
  • 2
    $\begingroup$ @SilvioMayolo "This date" isn't random. They just use sequential 2-digit numbers for each field in the date. You only have to remember the order of fields, which I guess they thought would be intuitive for Americans. $\endgroup$
    – Barmar
    Commented Mar 4 at 21:10
  • 5
    $\begingroup$ I am an American and I would have to look up that date every time. There's nothing intuitive about the order. $\endgroup$ Commented Mar 4 at 21:34
  • 3
    $\begingroup$ FWIW, the ISO date standard is YYYY-MM-DD, which disambiguates itself from the American convention. (Note the dashes and 4-digit year.) $\endgroup$
    – user76284
    Commented Mar 17 at 19:12

0

You must log in to answer this question.

Browse other questions tagged .