2

date seems to have a very odd default format in the US locale: Thu Jul 9 17:00:00 EDT 2020 using a space-padded day-of-month and putting the (24-hour!) time in the middle, between the month+day and the year.

Is this some sort of standard? Where does it come from?

8
  • to the person voting to close this as request for tutorials: the close reason explicitly excludes questions aimed at finding the official documentation behind something. So, this question should not be closed under that close reason! Commented Jan 25, 2022 at 13:09
  • There is no output standard. date "just growed", since the very beginning of Unix. If you're planning on parsing date, don't do it. Use the stat command instead. Read man stat.
    – waltinator
    Commented Jan 25, 2022 at 13:42
  • @waltinator I'm not planning on parsing date. I'm dealing with a different piece of software that takes its output format (but not implementation) from date, and I was wondering how we ended up with such an odd format. Still, at some point, there must have been a decision to put the elements in that funny order.
    – Adám
    Commented Jan 25, 2022 at 13:44
  • What US locale are you referring to? I assume it's an English language one? On what system? Commented Jan 25, 2022 at 14:44
  • @StéphaneChazelas en_US Try it online!
    – Adám
    Commented Jan 25, 2022 at 14:50

1 Answer 1

3

The format is defined in a standard, but that standard doesn’t specify en_US. It’s specified in POSIX, which only cares about the POSIX locale, and states that

When no formatting operand is specified, the output in the POSIX locale shall be equivalent to specifying:

date "+%a %b %e %H:%M:%S %Z %Y"

Historically (e.g. in Unix V7), date used asctime, which uses a different format:

Sun Sep 16 01:03:52 1973\n\0

The POSIX format adds the timezone between the time and year.

I don’t know the history of the POSIX-defined format, but I imagine it’s intentionally based on the asctime-based format.

The history of asctime can at least be explored, even if the reasoning can’t necessarily be ascertained.

Up to V3, ctime produced output of the form

Oct  9 17:32:24\0

V4 added the weekday and year, surrounding the format above and producing the format still used by asctime:

Sun Sep 16 01:03:52 1973\n\0

So it seems the format grew “organically”. At first it included only the month, day in month, and time. When the weekday and year were added, it appears that the existing format was preserved, so the weekday was prepended and the year appended. Finally, when the timezone was added, it was presumably perceived as related to the time rather than the year...

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .