date - Display the date and time

Format

date [-cu ] [+format]

Description

date displays the operating system's concept of the current date and time. The following example shows the default format of the date:
Wed Feb 26 14:01:43 EST 1986

Options

date accepts the following options:
-c
Displays the date and displays the time according to Greenwich Mean Time (Coordinated Universal Time) using CUT as the time zone name.
-u
Displays the date and displays the time according to Greenwich Mean Time (Coordinated Universal Time) using GMT as the time zone name.
If the argument to date begins with a + character, date uses format to display the date. date writes all characters in format, except for the % and the character that immediately follows it, directly to the standard output. After date exhausts the format string, it outputs a newline character. The % character introduces a special format field similar to the printf() function in the C library. date supports the following field descriptors:
%A
The full weekday name (for example, Sunday).
%a
The three-letter abbreviation for the weekday (for example, Sun).
%B
The full month name (for example, February).
%b
The three-letter abbreviation for the month name (for example, Feb).
%C
The first two digits of the year (00 to 99).
%c
The local representation of the date and time (see %D and %T).
%D
The date in the form mm/dd/yy.
%d
The two-digit day of the month as a number (01 to 31).
%e
The day of the month in a two-character, right-aligned, blank-filled field.
%H
The two-digit hour (00 to 23).
%h
The three-letter abbreviation for the month (for example, Jun).
%I
The hour in the 12-hour clock representation (01 to 12).
%j
The numeric day of the year (001 to 366).
%M
The minute (00 to 59).
%m
The month number (01 to 12).
%n
The newline character.
%p
The local equivalent of AM. or PM.
%r
The time in AM-PM notation (11:53:29 a.m.).
%S
The seconds (00 to 61). There is an allowance for two leap seconds.
%T
The time (14:53:29).
%t
A tab character.
%U
The week number in the year, with Sunday being the first day of the week (00 to 53).
%W
The week number in the year, with Monday being the first day of the week (00 to 53).
%w
The weekday number, with Sunday being 0.
%X
The local time representation (see %T).
%x
The local date representation (see %D).
%Y
The year.
%y
The two-digit year.
%Z
The time zone name (for example, EDT).
%%
A percent-sign character.
The date command also supports the following modified field descriptors to indicate a different format as specified by the locale indicated by LC_TIME. If the current locale does not support a modified descriptor, date uses the unmodified field descriptor value.
%EC
The name of the base year (period) in the alternative representation of the current locale.
%Ec
The current locale's alternative date and time representation.
%Ex
The current locale's alternative date representation.
%EY
The full alternative year representation.
%Ey
The offset from %EC (year only) in the alternative representation of the current locale.
%Od
The day of the month using the alternative numeric symbols of the current locale.
%Oe
The day of the month using the alternative numeric symbols of the current locale.
%OH
The hour (24-hour clock) using the alternative numeric symbols of the current locale.
%OI
The hour (12-hour clock) using the alternative numeric symbols of the current locale.
%OM
The minutes using the current locale's alternative numeric symbols.
%Om
The month using the current locale's alternative numeric symbols.
%OS
The seconds using the current locale's alternative numeric symbols.
%OU
The week number of the year (0-53) (with Sunday as the first day of the week) using the alternative numeric symbols of the current locale.
%OW
The week number of the year (0-53) (with Monday as the first day of the week) using the alternative numeric symbols of the current locale.
%Ow
The weekday as a number using the current locale's alternative numeric symbols (Sunday=0).
%Oy
The year (offset from %C) using the current locale's alternative numeric symbols.

Examples

The command:
date '+%a %b %e %T %Z %Y'
produces the date in the default format as shown at the start of this command description.

Environment variables

date uses the following environment variables:
TZ
Gives the time zone for date to use when displaying the time. This option is ignored if you specify either the -c or the -u option.

Localization

date uses the following localization environment variables:
  • LANG
  • LC_ALL
  • LC_CTYPE
  • LC_MESSAGES
  • LC_TIME
  • NLSPATH

Exit values

0
Successful completion.
>0
Failure due to any of the following reasons:
  • An incorrect command-line option.
  • Too many arguments on the command line.
  • A bad date conversion.
  • A formatted date that was too long.
  • You do not have permission to set the date.

Messages

Possible error messages include:
Bad format character x
A character that follows % in the format string was not in the list of field descriptors.
No permission to set date
The system denied you the right to set the date.

Portability

POSIX.2, X/Open Portability Guide, UNIX systems.

The -c option is an extension of the POSIX standard.

Related information

touch