The date command is used to print the date in a specified format. The date command will print the date based on the /etc/localtime file. By default, it will print the date in the following format:

[day of week] [month] [day] [24 hour time ##:##:##] [time zone] [year]
Wed Oct 31 15:03:16 GMT 2018

You can also format the time using a number of different formatting options. You initialize the formatting options with a plus sign (+), and each option is prefaced with a percent sign (%). For example, to retrieve the week number (out of 52 weeks a year), you’d enter date +%V

You can also use the date command to change the system’s date by including the -s option with a provided argument.

Syntax

The syntax of the date command is:

# date [options] [format]

Formatting Options

The following table lists some of the formatting options available.

Formatting Option Prints
%A The full weekday name.
%B The full month name.
%F The date in YYYY-MM-DD format.
%H The hour in 24-hour format.
%I The hour in 12-hour format.
%j The day of the year.
%S Seconds.
%V The week of the year.
%x The date representation based on the locale.
%X The time representation based on the locale.
%Y The year.

date Command Examples

1, To display the date and time:

2. To display the date and time entered by time:

# date --date=hh:mm:dd:mm:yy

3. To print the date from formats specified in each line of file:

# date -f file.txt
# date --file file.txt

4. To get the last modification time for a file:

5. To output date and time in RFC 2822 format:

# date -R
# date --rfc-2822

6. To output date and time in RFC 3339 format:

7. To set the time specified by the time:

# date -u
# date --utc
# date --universal

8. To display the version information: