Command-line Knowledge Base

date

Example 1/2
$ date +%F
$ 2021-01-08
Example 2/2
$ MONTH_NAME=$(date +%B)
$ echo $MONTH_NAME
$ January

Seconds

SequenceExampleDescription
%S 00..60 seconds
NULL NULL NULL
NULL NULL NULL

Minutes

SequenceExampleDescription
%M 00..59 minutes
NULL NULL NULL
NULL NULL NULL

Hour

SequenceExampleDescription
%H 00..23 hour
%I 00..12 hour
%k 0..23 hour, space padded; same as %_H
%l 1..12 hour, space padded; same as %_I

Day

SequenceExampleDescription
%d 01 day of month
%e  8 day of month, space padded; same as %_d
%a Sun locale's abbreviated weekday name
%A Sunday locale's full weekday name
%j 001..366 day of year
%u 1..7 day of week; 1 is Monday
%w 0..6 day of week; 0 is Sunday

Week

SequenceExampleDescription
%U 00..53 week number of year, with Sunday as first day of week
%W 00..53 week number of year, with Monday as first day of week
%V 01..53 ISO week number, with Monday as first day of week

Month

SequenceExampleDescription
%m 01..12 month
%b Jan locale's abbreviated month name
%B January locale's full month name

Year

SequenceExampleDescription
%g 21 last two digits of year of ISO week number (see %G)
%G NULL year of ISO week number (see %V); normally useful only with %V
%y 00..99 last two digits of year
%Y 2021 year
NULL NULL NULL

Date

SequenceExampleDescription
%D 01/08/21 date; same as %m/%d/%y
%F 2021-01-08 full date; like %+4Y-%m-%d
%x 2021-01-11 locale's date representation

Time

SequenceExampleDescription
%r 03:10:13 PM locale's 12-hour clock time
%R 15:11 24-hour hour and minute; same as %H:%M
%T 15:31:05 time; same as %H:%M:%S
%X 05:55:20 AM locale's time representation
NULL NULL NULL

Date and Time

SequenceExampleDescription
%c Fri 08 Jan 2021 08:16:27 AM locale's date and time

Time Zone

SequenceExampleDescription
%z -0400 +hhmm numeric time zone
%:z -04:00 +hh:mm numeric time zone
%::z -04:00:00 +hh:mm:ss numeric time zone
%:::z -04, +05:30 numeric time zone with : to necessary precision
%Z EST alphabetic time zone abbreviation

Misc

SequenceExampleDescription
%n   a newline
%t   a tab
%p   locale's equivalent of either AM or PM; blank if not known
%P   like %p, but lower case
%q 1..4 quarter of year
- %-d (hyphen) do not pad the field
_   (underscore) pad with spaces
0   (zero) pad with zeros
+   pad with zeros, and put '+' before future years with >4 digits
^   use upper case if possible
#   use opposite case if possible