You can change the date format in the date command by using format specifiers. Here’s how to do it:
- Use the
datecommand followed by the+sign and your desired format in quotes.
Here are some examples of custom date formats:
-
Standard format (YYYY-MM-DD HH:MM:SS):
date "+%Y-%m-%d %H:%M:%S" -
12-hour clock format:
date "+%I:%M:%S %p" -
Including the day of the week:
date "+%A, %B %d, %Y" -
Compact date format:
date "+%y%m%d"
You can experiment with these formats by typing them in your terminal. The + sign indicates that you are specifying a custom format. For a full list of formatting options, you can refer to the manual page by typing man date in the terminal.
