date

Display or set the date and time (POSIX)

Syntax:

Display the date and time:

date [-tuv] [-s seconds] [+format]

Set the date and time:

date [-uv] [-S seconds] date

Runs on:

QNX Neutrino, Microsoft Windows

Options:

-S seconds
Set the maximum number of seconds (of real time) over which date is to adjust the time. The date utility doesn't increase the clock speed by more than 100% or decrease it by more than 50%. If date can't do a slow adjustment within those constraints, the time is changed immediately. (The default is 300 seconds; use -S0 to disable the gradual adjustment.)
-s seconds
Display the string equivalent of this date, supplied as seconds since the start of the Epoch (00:00 January 1, 1970). This value is used instead of the system time value for the number of seconds.
-t
Display the current operating system time, in seconds since the start of the Epoch, as a long integer.
-u
Perform operations using Coordinated Universal Time (UTC) instead of local time. UTC is the standard term for Greenwich Mean Time (GMT).
-v
Be verbose.
date
A date specification to set the date to. Only the superuser (root) can change the date. For more information, see Setting the date,” below.
+format
The format in which the date and time are to be displayed.

Description:

The date utility is used to display and set the current system date and time in software. Only the superuser (root) may use date to set the time.

Displaying the date

The date utility normally displays the current date and time according to the operating system's internal time, maintained in software as the number of seconds since the Epoch (00:00 January 1, 1970). When the -s seconds option is used, date uses the value specified by the seconds argument instead of the current OS time.

You can specify the format and content of the displayed date and time with the +format option. The format is composed of ASCII characters and field descriptors prefaced with %, in a manner similar to a C-language printf() format specifier (the specific characters used to specify field types are, however, completely different). In the output, each field descriptor is replaced by its corresponding value; all other characters are copied to the output without change.

Note: This utility uses strftime(), a libc library function, to format the time into a string. For a complete list of the field descriptors you can use in the +format option, see strftime() in the C Library Reference.

The date utility always terminates its output with a newline character.

Setting the date

If you're a system administrator running as root, you may use date to set the system time. To set the hardware clock to match the current system time set by date, you should use the rtc utility.

Note: Be careful if you set the date during the period that a time zone is switching from daylight saving time to standard time. When a time zone changes to standard time, the local time goes back one hour (for example, 2:00 a.m. becomes 1:00 a.m.). The local time during this hour is ambiguous (e.g., 1:14 a.m. occurs twice in the morning that the time zone switches to DST). To avoid problems, use UTC time to set the date in this period.

By default, if the new time is in the range of:

(-2.5 minutes + old time, 5 minutes + old time)

the date utility makes a “slow adjustment”; it increases the clock speed by less than 100% or decreases the clock speed by less than 50% over a period of time from 1 second to 5 minutes until the clock catches up with the new time. This slow adjustment doesn't cause major discontinuities in the time flow. You can disable the slow adjustment by using the -S0 option.

The date utility recognizes this format for setting the time:

where:

CC
Century (e.g., 19 if the year is 1997)
YY
Year modulo 100 (e.g., 97 if the year is 1997). When the century is not specified (with CC), the years 69-99 are 1969 to 1999, and 00-68 are 2000 to 2068.
MM
Numerical month of the year (01 for January, 02 for February, etc.)
DD
Day of the month
hh
Hour of the day
mm
Minute of the hour
SS
Seconds of the minute

If you change the date or time, date adds a a line to the /var/log/wtmp if it already exists.

Note: The date utility doesn't create /var/log/wtmp if it doesn't already exist. This file can quickly become very big, which isn't good on an embedded system with limited resources.

Examples:

Set the system date to 22 February 1997:

$ date 0222000097

Set the system date and time to 11 May 2017, 4:30 pm:

$ date 051116302017

Files:

/var/log/wtmp
If you change the data or time, and this file already exists, an entry is added to it to log the change.

Environment variables:

TZ
Specifies the local time zone. The value of TZ affects the conversion between the system clock (UTC) and the local time.

Exit status:

0
The date was displayed or set successfully.
>0
An error occurred.

Caveats:

Some field descriptors are of undefined format when not in the POSIX locale. As a result, parsing the output of date may be difficult in other locales. QNX Neutrino currently supports only the POSIX (i.e., C) locale.