Unless otherwise specified, date normally pads numeric fields with zeros, so that, for example, numeric months are always output as two digits. Seconds since the epoch are not padded, though, since there is no natural width for them.
As a GNU extension, date recognizes any of the following optional flags after the ‘%’:
Here are some examples of padding:
date +%d/%m -d "Feb 1" ⇒ 01/02 date +%-d/%-m -d "Feb 1" ⇒ 1/2 date +%_d/%_m -d "Feb 1" ⇒ 1/ 2
As a GNU extension, you can specify the field width (after any flag, if present) as a decimal number. If the natural size of the output of the field has less than the specified number of characters, the result is written right adjusted and padded to the given size. For example, ‘%9B’ prints the right adjusted month name in a field of width 9.
An optional modifier can follow the optional flag and width specification. The modifiers are:
If the format supports the modifier but no alternate representation is available, it is ignored.