10

The date command outputs the current date and time like this: Fri Apr 12 15:04:03 UTC 2013.

To have the output date-time in a custom format we can use date +FORMAT, for example, like this: date "+%Y-%m-%dT%H:%M:%S%:z" which gives something like 2013-04-12T15:04:37+00:00.

But I want to know what the %Y, %m, %d, %H, %M, %S, etc. are collectively called (i.e. the terminology). Also, what's the T called, as it's different from the rest?

5
  • 3
    “FORMAT controls the output. Interpreted sequences are…” – man date And the “T” is just a literal “T”.
    – manatwork
    Apr 12, 2013 at 15:23
  • @manatwork In the man page, I thought the sequences refer to both the %Y and their respective meaning.
    – its_me
    Apr 12, 2013 at 16:15
  • Tip: date +"You will die in the year %Y"
    – Izkata
    Apr 12, 2013 at 20:05
  • @Izkata Makes no sense(?)
    – its_me
    Apr 13, 2013 at 1:44
  • 1
    @TheoneManis Just an example of that T not being special. Also, I was having a weird day at work when I typed that (listening to co-workers' conversations).
    – Izkata
    Apr 13, 2013 at 1:53

4 Answers 4

8

The term used in the POSIX specification of the date command is "conversion specifications".

The format string for the date command is closely based on the format string for C's printf function; the C standard also refers to things like %d as "conversion specifications".

T not preceded by % is just a character: "All other characters shall be copied to the output without change."

According to the change history section of the POSIX description of date:

The DESCRIPTION is updated to refer to conversion specifications, instead of field descriptors for consistency with the LC_TIME category.

So apparently an earlier version of the specification used the phrase "field descriptors", but "conversion specifications" is the current official term.

Of course that doesn't mean you have to refer to them that way.

2
  • Are "conversion sequences" or "format sequences" appropriate terms too? I am considering sequences over specifications 'cause it's actually mentioned in the man page for date.
    – its_me
    Apr 12, 2013 at 16:31
  • 2
    @TheoneManis: Any of the three seems sufficiently obvious about what it means. Apr 12, 2013 at 17:09
4

I would think "escape sequences" or (in this case) "special characters for percent-escaped sequences" would be the typical way of referring to them. Backslash-and percent-escaped sequences are much used in C (e.g. printf), so they've filtered into several Unix-commands too (like specifying the prompt for the shell).

The "escape sequence" being "%Y", "%m", "%d" and so on; and the "special characters" being "Y", "m", "d" and so on. "%" would be the "escape character" (the character that gives the following character an unusual/special meaning).

3

This document from IBM's Information Center clearly states that the alphabets in %Y, %m, %d, %H, %M, %S, etc. are called "Field Descriptors".

You must precede each field descriptor with a % (percent sign). The system replaces the field descriptor with the specified value. [...] The date command copies any other characters to the output without change.

That answers my two questions (about %n & T). And I believe this is as authoritative as it can get.

1
  • 2
    IBM didn't invent the date command; what makes their documentation authoritative? The command's behavior is currently defined by POSIX, which doesn't use that term. The change history at the bottom of the POSIX description says "The DESCRIPTION is updated to refer to conversion specifications, instead of field descriptors for consistency with the LC_TIME category.", implying that "conversion specification", not "field diescriptor" is the correct current term. See also my updated answer. Apr 17, 2013 at 17:21
2

As others have stated, the T is a literal letter T. But to be specific, your example date "+%Y-%m-%dT%H:%M:%S%:z" appears to be a format string conforming to the ISO-8601 specification for date and time. So here the T is a delimiter that separates the date from the time.

You must log in to answer this question.

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