Date and time formatting characters are listed with explanation of their meaning in manual pages of ckdate and cktime commands. However, those man pages are for whatever reasons incomplete and some useful formats are omitted.
Korns script dt listed below displays all more a less meaningful date command formatting characters (those formats that produce result different from themselves, i.e. formats that get interpreted). Script is relatively small and is presented as a function that could be defined in .profile file, which is normally executed automatically at user login.
# -------- Display Date and Time Formatting Characters -------------------------
function dt { echo Date and Time Formatting Characters
date
A=" a b c d e f g h i j k l m n o p q r s t u v w x y z"
A="$A A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"
for C in $A
do D=$(date +%$C)
if [[ "$D" != %$C ]]
then echo date +%$C -- $D
fi
done
unset A C D; }
# dt
Date and Time Formatting Characters
Fri Oct 12 21:48:11 EDT 2001
date +%a -- Fri . . . . . . . .
date +%b -- Oct . . . . . . . .
date +%c -- Fri Oct 12 21:48:12 2001
date +%d -- 12 . . . . . . . .
date +%e -- 12 . . . . . . . .
date +%h -- Oct . . . . . . . .
date +%j -- 285 . . . . . . . .
date +%k -- 21 . . . . . . . .
date +%l -- 9 . . . . . . . .
date +%m -- 10 . . . . . . . .
date +%n --
date +%p -- PM . . . . . . . .
date +%r -- 04:48:12 PM . . . . .
date +%t --
date +%u -- 6 . . . . . . . . .
date +%w -- 5 . . . . . . . . .
date +%x -- 10/12/01 . . . . . .
date +%y -- 01 . . . . . . . .
date +%A -- Friday . . . . . . .
date +%B -- October . . . . . . .
date +%C -- Fri Oct 12 21:48:13 EDT 2001
date +%D -- 10/12/01 . . . . . .
date +%E -- %_=/usr/bin/date
date +%H -- 21 . . . . . . . .
date +%I -- 09 . . . . . . . .
date +%M -- 48 . . . . . . . .
date +%O -- %_=/usr/bin/date
date +%R -- 21:48 . . . . . . .
date +%S -- 14 . . . . . . . .
date +%T -- 21:48:14 . . . . . .
date +%U -- 40 . . . . . . . .
date +%V -- 41 . . . . . . . .
date +%W -- 41 . . . . . . . .
date +%X -- 21:48:14 . . . . . .
date +%Y -- 2001 . . . . . . . .
date +%Z -- EDT . . . . . . . .
|
Default date format Day of a week abbreviated name Month of a year abbreviated name Full current date (without time zone) Day number within current month (01–31) Day number within current month (1–31) Month of a year abbreviated name Day number within the current year (001-366) Hour military (24 hour scale: 0-23) Hour AM/PM (1–12) Month number within the current year (01-12) Insert New Line character Ante Meridian / Post Meridian indicator Current time HH:MM:SS AM/PM Insert Tab character Day of a week number (1-7, Sunday=7) Day of a week number (0-6, Sunday=0) Current date MM/DD/YY Year number within the current century (00-99) Day of a week full name Month of a year full name Full current date with time zone Current date MM/DD/YY Hour military (24 hour scale: 00–23) Hour AM/PM (01–12) Minute within the current hour (00–59) Current time HH:MM military (24 hour) Second within current minute (00–59) Current time HH:MM:SS military (24 hour) Number of full weeks since year beginning Week number within the current year (01-53) Week number within the current year (01-53) Current time HH:MM:SS military (24 hour) Full current year CCYY (century and year) Current time zone acronym |
# date +%Y%m%d . . . . . . . .
20011029
# date +%Y-%m-%d . . . . . . .
2001–10–29
# date +%D %R . . . . . . . .
10/29/01
# date '+%D %R' . . . . . . .
10/29/01 13:36
# date '+%A, %B %d %Y %I:%M %p' . .
Monday, October 29 2001 01:44 PM
|
Use combination of format elements Use symbols to delimit format elements Second part of format is ignored (due to interfering spaces) Use single quotes to insert spaces Combine any format elements with symbols |