date - display or set date and time
When invoked without arguments, the date utility displays the current date and time.
Otherwise, depending on the options specified, date will set the date and time or print it
in a user-defined way.
Below are few best questions on date command.
Q. Print today's date with day of the week, current time, timezone and year?
date
Q. Print "30 minute ago's" time, date with day of the week, timezone and year?
date --date='30 minutes ago'
-d is short hand for --date
date -d '15 hour ago'
date -d '-10 day'
date -d '1 month ago'
date -d '-1 year'
Q. Print time and date 30 minute from now in future?
date --date='30 minutes'
-d is short hand for --date
date -d '15 hour'
date -d '10 day'
date -d '1 month'
date -d '+1 year'
Q. Display date in format month/day/year(mm/dd/yy)?
date +%D
Q. Display time in format hour:minutes:seconds(hh/mm/ss)?
date +%T
date +%m : Displays month number(mm)
date +%d : Displays day of the month(dd)
date +%y : Displays year(yy)
date +%Y : Displays year(yyyy)
date +%H : Displays Hour
date +%M : Displays Minutes
date +%S : Displays Seconds
date +%h : Displays abbreviated month(Jan-Dec)
Q. Display date in format month/day/year(dd/mm/yy)?
date +%d/%m/%y
Q. How to set systems date and time?
date -s "08/27/2022 09:35:24"
Q. Display date in timezone America/New_York?
TZ=America/New_York date
Q. Display date in UTC timezone?
TZ=UTC date
Q. Display epoch (seconds since 1970-01-01 00:00:00 UTC)?
date +%s