The date
command is a useful tool for displaying and formatting the current date and time in Unix. Here are a few examples of how you can use the date
command:
date
command without any options:date
This will output the current date and time in the format Wed Dec 22 16:40:53 EST 2021
.
+
option to specify a custom format string. For example, to display the date and time in the format YYYY-MM-DD HH:MM:SS
, you can use the following command:date +%Y-%m-%d %H:%M:%S
This will output the current date and time in the format 2021-12-22 16:40:53
.
-s
option followed by the date and time in the format YYYY-MM-DD HH:MM:SS
. For example, to set the system clock to January 1, 2022 at 12:00:00, you can use the following command:date -s "2022-01-01 12:00:00"
This will set the system clock to the specified date and time.
Overall, the date
command is a simple and convenient tool for displaying and formatting the current date and time in Unix. It has many other options and features that allow you to customize its behavior and output.