dateset and display date and time |
Command |
|
date
[
-ctu
] [
timespec]
date
[
-cu
]
[
+
format]
date
either displays the operating system's idea of the
current date and time or sets it to a new value. The following example shows the
default format of the date:
Wed Feb 26 14:01:43 EST 1998
-c
sets or displays the date and time according to Greenwich Mean Time
(Coordinated Universal Time) using CUT
as the time zone
name.
-t
specifies that the BSD format is used when setting the date and
time.
-u
sets or displays the date and time according to Greenwich Mean Time
(Coordinated Universal Time) using GMT
as the time zone
name.
date
also accepts an argument in one of two forms. If the
argument does not begin with
+
,
date
assumes it is a
timespec to set the date and time. The
timespec
can have the form
[[mm]dd]hhmm[.ss]
or
mmddhhmmyy[.ss]
where
mm is the optional number of the month (01-12),
dd is the optional day of the month,
hh is the hour in 24 hour format (required)
mm is the minutes (required),
yy is the optional last 2 digits of the year, and
ss is the optional seconds.
date
uses these values to set the date and time.
- Note:
You must specify the hours and the minutes; other arguments are
optional. The year can be specified only if you have specified the month
and day.
The
-t
option allows you to use the BSD date format, which
is:
[[[[cc]yy]mm]dd]hhmm[.ss]
where
cc is the optional first 2 digits of the year.
If the argument to
date
begins with a
+
character,
date
uses
format to display the date.
date
writes all characters in
format, with the
exception of the
%
and the character which 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 (see
Field Descriptors).
%A
- the full weekday name in the current locale (for example, Sunday, in the
POSIX locale).
%a
- the abbreviation for the weekday in the current locale (for example, Sun,
in the POSIX locale).
%B
- the full month name in the current locale (for example, February, in the
POSIX locale).
%b
- the abbreviation for the month name in the current locale (for example,
Feb, in the POSIX locale).
%C
- the first two digits of the year (19 or 20).
%c
- the appropriate representation of the date and time in the current locale.
%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-digit, right-justified, blank-filled field
( 1 to 31).
%H
- the hour in the 24-hour clock representation (00 to 23).
%h
- the same as
%b
.
%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
- a newline character.
%p
- the equivalent of AM or PM in the current locale.
%R
- the 24-hour time (for example, 14:53).
%r
- the 12-hour time in the current locale's equivalent of AM/PM notation (for
example, 11:53:29 AM in the POSIX locale).
%S
- the seconds (00 to 61). Note that there is an allowance for two leap
seconds.
%T
- the 24-hour time (for example, 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). All days before the first Sunday of the new year are in week
0.
%u
- the weekday number with Monday being 1 and Sunday being 7.
%V
- the week number in the year, with Monday being the first day of the week
(01 to 53). If the week containing January 1 has four or more days in the
new year, it is week 1 of the new year; otherwise it is week 53 of the
previous year.
%W
- the week number in the year, with Monday being the first day of the week
(00 to 53). All days before the first Monday of the new year are in week
0.
%w
- the weekday number, with Sunday being 0 and Saturday being 6.
%X
- the appropriate time representation in the current locale.
%x
- the appropriate date representation in the current locale.
%Y
- the four-digit number of the year (for example, 1998).
%y
- the two-digit year (offset from
%C
).
%Z
- the time zone name (for example,
EDT
).
%z
- equivalent to
%Z
.
%%
- 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 current locale's alternate
representation.
%Ec
- the current locale's alternate date and time representation.
%EX
- the current locale's alternate time representation.
%Ex
- the current locale's alternate date representation.
%EY
- the full alternate year representation.
%Ey
- the offset from
%EC
(year only) in the current locale's
alternate representation.
%Od
- the day of month using the current locale's alternate numeric symbols.
%Oe
- the day of month using the current locale's alternate numeric symbols in a
two-character, right-justified, blank-filled field.
%OH
- the hour (24-hour clock) using the current locale's alternate numeric
symbols.
%OI
- the hour (12-hour clock) using the current locale's alternate numeric
symbols.
%OM
- the minutes using the current locale's alternate numeric symbols.
%Om
- the month using the current locale's alternate numeric symbols.
%OS
- the seconds using the current locale's alternate numeric symbols.
%OU
- the week number of the year (with Sunday as the first day of the week)
using the current locale's alternate numeric symbols.
%Ou
- the weekday number using the current locale's alternate numeric symbols
with Monday being 1 and Sunday being 7.
%OV
- the week number in the year using the current locale's alternate numeric
symbols, with Monday being the first day of the week. If the week
containing January 1 has four or more days in the new year, it is week 1
of the new year; otherwise it is week 53 of the previous year.
%OW
- the week number of the year (with Monday as the first day of the week)
using the current locale's alternate numeric symbols.
%Ow
- the weekday as a number using the current locale's alternate numeric
symbols with Sunday being 0 and Saturday being 6.
%Oy
- the year (offset from
%C
) using the current locale's
alternate numeric symbols.
The command
date '+%a %b %e %T %Z %Y'
produces the date in the default format. For example,
Wed Feb 26 14:01:43 EST 1998
TZ
gives the time zone for date
to use when displaying
the times. This is ignored if you specify either the -c
or the -u
option. For more information on this
variable, see timezone
.
Possible exit status values are:
0
Successful completion.
1
Failure due to any of the following:
- — a bad date conversion
- — a formatted date that was too long
- — you do not have permission to set the date
2
Usage error, including:
- — an invalid command line option
- — too many arguments on the command line
Possible error messages include:
- Bad date conversion: "string"
The date and/or time specified on the command line had an invalid
format (for example, if the hour is greater than 24).
- Bad format character x
A character following %
in the format string was
not in the list of field descriptors.
- No permission to set date
The system has denied you the right to set the date.
POSIX.2.
x/OPEN Portability Guide 4.0.
The
-c
option, the
-t
option, and the
%z
format specifier are extensions to both the POSIX and
x/OPEN standards. The
%R
format specifier is an
x/OPEN extension to the POSIX standard.
On machines that have a time-of-day clock with battery backup, using
date
does not necessarily change this real-time clock.
There is probably an operating system-specific command to achieve this.
- Commands:
touch
- Miscellaneous:
timezone