Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

date - write the date and time

&pagelevel(4)&pagelevel

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



Format 1: date[ -u][ +format]


No argument specified

date prints the current date and time in a format governed by the current locale.

-u

Displays the current date and time in UTC.

If the -u option is set, the +format specification is ignored.

+format

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. 

Format 2: date -a[ -] sss.fff


-a[ -] sss.fff

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.


%n newline character
%t tab character
%c date and time in the default format of the current locale
%C century (first two digits of the year, 00-99)
%D date in the format %m/%d/%y
%x date in the format of the current locale
%y year (last two digits of the year, 00-99)
%Y year (last two digits of the year, 00-99)
%m month
%h month (in letters, abbreviated) in the format of the current locale
%b identical to %h
%B month (in letters, in full) in the format of the current locale
%W week number of year (00 to 53, with Monday as the first day of the week)
%V week number of the year (01 to 53, with Monday as the first day of the week). 
The first week in January is counted as week 1 if it contains at least 4 days. 
Otherwise this week is counted as week 53 of the previous year.
%U week number of the year (00 to 53, with Sunday as the first day of the week)
%j day of year (001 to 366)
%d day of month (01 to 31)
%e day of month (1 to 31, single-digit numbers preceded by a blank)
%a abbreviated weekday name in the format of the current locale
%A full weekday name in the format of the current locale
%w day of week (0 to 6, Sunday = 0)
%u day of week (1 to 7, Monday = 1)
%R time in the format %H:%M
%T time in the format %H:%M:%S
%X time in the format of the current locale
%r time in a.m./p.m. notation, as %I:%M:%S %p
%H hour (00 to 23)
%I hour (01 to 12)
%p string containing ante-meridiem or post-meridiem indicator(a.m./p.m. affix)
in the format of the current locale.
%M minute (00 to 59)
%S second (00 to 61)
%Z timezone name, or no output if no timezone exists (governed by the value
of the environment variable TZ, see POSIX shell variables).

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.


%Ec date and time in the alternative format
%EC name of the time period (e.g. "year") in the alternative representation
%Ex date in the alternative format
%EX time in the alternative format
%Ey year in which the time period in the alternative representation begins
%EY year in the alternative representation
%Od day of month in alternative numeric representation
%Oe day of month in alternative numeric representation
%OH hour (24-hour clock) in alternative numeric representation
%OI hour (12-hour clock) in alternative numeric representation
%Om month in alternative numeric representation
%OM minutes in alternative numeric representation
%OS seconds in alternative numeric representation
%Ou weekday in the alternative format (Monday = 1)
%OU week of the year in alternative numeric representation (same as for %U)
%OV week of the year in alternative numeric representation (same as for %V)
%Ow weekday in the alternative format (Sunday = 0)
%OW week of the year in alternative numeric representation (same as for %W)
%Oy year in the alternative format

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 "MEZ-1MSZ-2,M3.5.0/02:00:00,M10.5.0/03:00:00" of the TZ variable must be interpreted as following:


Standard time zone

NameMEZ

Time differenceZone - 01:00:00 = UTC

Alternative time zone

NameMSZ

Time differenceZone - 02:00:00 = UTC

Switchover time to the alternative time zone

Month3 = March

Week5 (or 4)

Weekday0 = Sunday

Time02:00:00

Switchover time to the standard time zone

Month10 = October

Week5 (or 4)

Weekday0 = Sunday

Time03:00:00

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
If you call date without arguments at 17:00 hours EST on June 19, 2009, and the system clock is set to the correct time, the following will be printed


Fri Jun 19 17:00:00 MSZ 2009


The command:


$ date '+DATE: %m/%d/%y%nTIME: %H:%M:%S'


generates the following output:


DATE: 06/19/09

TIME: 17:00:00

See also  

cal
ctime(), printf() [4]