date writes the current date and time on standard output.
The form in which date outputs dates and times depends on the value of the environment variable LC_TIME or, if that is undefined or null, on the value of LANG. If both are undefined or null, or if the required database is not available, or if one of the NLS variables has an invalid value, date acts as if in a non-internationalized system, printing dates and times in American format.
Mode of operation
The system works with UTC (Coordinated Universal Time; this is the same as GMT - Greenwich Mean Time). date converts UTC to local time and vice versa. If the environment variable TZ is defined and option -u is not set then this variable is used to determine the time zone and convert UTC to local time.
Syntax
Format 1: |
date[ -u][ +format] |
Format 2: |
date -a[ -] sss.fff |
No argument specified date prints the current date and time in a format governed by the current locale.
Displays the current date and time in UTC. If the -u option is set, the +format specification is ignored.
The format argument defines the output format for date. If format contains blanks or tabs or other shell metacharacters which you do not want the shell to interpret, you should enclose format in single quotes: +'format'. format is essentially similar in format to the first argument of the printf() function in C or awk (see awk, printf and the C function printf()). The output of date can be formatted by means of field descriptors in the format argument. Field descriptors take the form of a percentage sign followed by a letter and are replaced in the output by their values. All characters that are not part of a field descriptor are copied to the output unmodified. The output is always terminated with a newline character. | ||
Adjusts the system clock time by sss.fff seconds, where fff represents fractions of a second. This adjustment can be positive or negative (-). The system's clock will be sped up or slowed down until it has changed by the specified amount. |
Field descriptors
The following overview lists all legal field descriptors. Although the field descriptors %h and %b are essentially identical, both descriptors have been retained for compatibility reasons.
|
Modified field descriptors
If an alternative representation is defined in your local environment(e.g. before and after Christ) you can call it using modified field descriptors. Modified field descriptors are in the form %Eletter or %Oletter. The modified field descriptors that can be used are listed in the overview below. If no alternative representation has been defined, all modified field descriptors output the value of the current unmodified field descriptors.
|
Variable
TZ If defined, the environment variable TZ contains information on timezones. date uses TZ to determine the timezone and to convert from UTC (Coordinated Universal Time) to local time and vice versa. The default value "
|
Locale
The following environment variables affect the execution of date: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments). LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. LC_TIME Determine the format and contents of date and time strings written by date. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES. |
Example
Printing date and time
The command:
generates the following output:
|
See also
cal |