date Command: Tutorial & Examples
Display the current date and time
The date
command is a Unix and Linux command used to display the current date and time, or to set the system date and time.
Here is the basic syntax for the date command:
date [options]
If you run the date command without any options, it will display the current date and time in the default format. For example:
date
Sat Dec 18 14:25:01 EST 2021
You can use the -u
option to display the date and time in Coordinated Universal Time (UTC) instead of the local time zone.
You can use the -d
option to specify a custom date and time in the format "YYYY-MM-DD HH:MM:SS"
. For example:
date -d "2022-01-01 00:00:00"
This would display the date and time "2022-01-01 00:00:00"
in the local time zone.
You can use the -s
option to set the system date and time. For example:
date -s "2022-01-01 00:00:00"
This would set the system date and time to "2022-01-01 00:00:00"
in the local time zone. Note that you must have superuser privileges to use the -s
option.
There are many other options and formatting specifiers available with the date
command. You can learn more about date by reading its documentation or by using the date --help
command.
CleverUptime uses the date
command to check if the time on your server is accurate. We also recommend to set the timezone to UTC, to avoid problems with multiple servers in
different timezones and difficulties handling daylight saving time.