Displays or sets the date or time.
/usr/bin/date [ -n ] [ -u ] [ Date ] [ +FieldDescriptor ... ]
/usr/bin/date [ -u ] [ +FieldDescriptor ... ]
/usr/bin/date [ -a [ + | - ]sss[.fff ]
The date command writes the current date and time to standard output if called with no flags or with a flag list that begins with a + (plus sign). Otherwise, it sets the current date. Only a root user can change the date and time. The date command prints out the usage message on any unrecognized flags or input.
The following formats can be used when setting the date with the Date parameter:
The variables to the Date parameter are defined as follows:
The current year is used as the default value when the year is not specified. The system operates in Coordinated Universal Time (CUT).
If you follow the date command with a + (plus sign) and a field descriptor, you can control the output of the command. You must precede each field descriptor with a % (percent sign). The system replaces the field descriptor with the specified value. Enter a literal % as %% (two percent signs). The date command copies any other characters to the output without change. The date command always ends the string with a new-line character.
The %E and %O field descriptors can be modified to indicate a different format or specification. If the corresponding keyword (see the era, era_year, era_d_fmt, and alt_digits keywords) is not specified or not supported for the current locale, the unmodified field descriptor value is used.
This command returns the following exit values:
| 0 | The date was written successfully. |
| >0 | An error occurred. |
date
date 0217142590
For a system using CST as its time zone, this sets the date and time to Sat Feb 17 14:25:00 CST 1990.
date +"%r %a %d %h %y (Julian Date: %j)"
This displays the date shown in Example 2 as:
02:25:03 PM Fri 17 Feb 90 (Julian Date: 048)
The following environment variables affect the execution of the date command.