The date command
This 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:
Specifies the month number.
Specifies the number of the day in the month.
Specifies the hour in the day (using a 24-hour clock).
Specifies the minute number.
Specifies the first 2 digits of the year.
Note: If you do not specify the first 2 digits of the year, values in the range 70 – 99 refer to the twentieth century, 1970 – 1999 inclusive, and values in the range 00 – 37
refer to years in the twenty-first century, 2000 – 2037 inclusive.
Specifies the last 2 digits of the year.
Note: The date command accepts a 4-digit year as input. For example, if a 4-digit year is specified, the date command tries to set the year to YYyy and fails for values that
are out of range (less than 1970 and greater than 2105). For years in the range 2038 – 2105, specify the year in the yyyy format.
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 following table lists the main literals that can be used to output formats to date:
|% To||Abbreviated name of the day|
|% A||Full name of the day|
|% B||Abbreviated month name|
|% B||Full month name|
|% C||Date and Time|
|% C||First two digits of the year, say 20, 2007|
|% D||Day of the month with two digits, eg 01|
|% D||Like indicate% m /% d /% y|
|% E||Day of the month with one or two digits, example 1, 10|
|% F||Complete, the same date as% Y-% m-% d|
|% H||b As%|
|% H||Time in 24-hour format with two digits (00..23)|
|% I||Time in 12-hour format with two digits (01..12)|
|% J||Day of year (001..366)|
|% K||Time in 24-hour format with one or two digits (0..23)|
|% L||Time in 12-hour format with one or two digits (1..12)|
|% M||Two-digit month (01..12)|
|% M||With double-digit minutes (00..59)|
|% R||Full Time in 12-hour format (eg 1:23:45)|
|% R||Hours and minutes in 24-hour format, the same as% H:% M|
|% S||Seconds since 01 / Jan / 1970 00:00:00 (epoch date)|
|% S||Two digit seconds (00..60)|
|% T||Full Time in 24-hour format (eg 13:23:45)|
|% U||Weekday number (1..7, 1 is Monday)|
|% U||Number of the week in the year, Sunday, first day of week (00..53)|
|% V||Number of the week in the year, Monday first day of week (01..53) Format ISO|
|% W||Weekday number (0..6, 0 is Sunday)|
|% W||Number of the week in the year, Monday first day of week (00..53)|
|% And||Last two digits of the year|
|% Y||Cutro digit year|
|% Z||Time or numeric time zone|
|% Z||Alphabetical zone or time zone abbreviation|
Unix_Tricks> date +%B/%A/%d/%y June/Sunday/24/07 Unix_Tricks> date +%d%m%y 240607 Unix_Tricks> cat lala.txt Unix_Tricks> date Sun June 24 22:01:28 CDT 2007 Unix_Tricks> date +%a dom Unix_Tricks> date +%A Sunday Unix_Tricks> date +%B%A JuneSunday Unix_Tricks> date +%B-%A June-Sun Unix_Tricks> date +%A-%B%-d June-Sunday-24 Unix_Tricks> date +%B-%A-%d-%Y June-24-2007-Sun Unix_Tricks> date +%B/%A/%d/%y June/Sunday/24/07 Unix_Tricks> date +%d%m%y 240607 Unix_Tricks>