You can use the -d
or --date
option to specify a custom date and time to display.
date --date="2022-12-25 12:00:00"
You can also use the +
option to specify a custom format for the output.
date +"%Y-%m-%d %H:%M:%S"
The date format option, +
, allows you to specify a custom format for the output of the date
command. There are a variety of formatting options available to use with the +
option. Some common options include:
%Y
- four-digit year (e.g. 2022)
%m
- two-digit month (e.g. 05 for May)
%d
- two-digit day of the month (e.g. 09)
%H
- two-digit hour (24-hour clock) (e.g. 16 for 4pm)
%M
- two-digit minute (e.g. 32)
%S
- two-digit second (e.g. 45)
%A
- weekday name (e.g. Monday)
%B
- month name (e.g. January)
You can use any combination of these options to create a custom date format. Here are some examples of how to use the +
option:
date +"%A %B %d, %Y"
date +"%H:%M:%S %Z"
## Output
Monday May 09, 2023
16:32:45 UTC