$ cat ./posts/aug-6,-2022

Linux date cheatsheet

Some quick handy formats that can be used with the date command on Linux.

#linux#cli

Some quick handy formats that can be used with the date command on Linux.

FormatDescription
%dDay of month (01..31)
%mMonth (01..12)
%YYear (4 digits)
%yYear (2 digits)
%HHour (00..23)
%MMinute (00..59)
%SSecond (00..60)
%TTime (HH:MM:SS)
%pAM or PM
%xLocale date (mm/dd/yy)
%sEpoch time

Examples

date +'%d'
06
date +'%m'
08
date +'%Y'
2022
date +'%m-%d-%Y'
08-06-2022
date +'%m/%d/%Y %H:%M:%S'
08/06/2022 21:12:40
date +'%m/%d/%Y %H:%M:%S %p'
08/06/2022 21:12:28 PM
date +'%x %T %p'
08/06/22 21:11:59 PM

Bonus — print current epoch time:

date +'%s'
1659820538

Reference: Chapter 10: Time, The Linux Programming InterfaceMichael Kerrisk