date

display or set the date and time (POSIX)

Syntax:

Display date and time:

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

Set date and time:

   date [-u] date

Options:

-s seconds
Display the string equivalent of this date, supplied as seconds since the start of the Epoch. This value is used instead of the system time value for the number of seconds.
-u
Perform operations using Coordinated Universal Time (UTC) instead of local time. UTC is the standard term for Greenwich Mean Time (GMT).
date
A date specification to set the date to. Only the superuser (root) can change the date.
+format
The format in which the date and time are to be displayed.

Examples:

The following are input/output examples of date used at arbitrary times in the POSIX locale:

Input:
date "+DATE: %m/%d/%y%nTIME: %H:%M:%S"
Output:
DATE: 11/21/97
TIME: 13:36:16
Input:
date "+TIME: %r"
Output:
TIME: 01:36:32 PM

The following are examples of date used to set the date and time:

Set the system date to 22 February 1997:

    date 22 2 97

Set the system date and time to 16 May 1997, 4:30 pm:

    date 16 may 1997 4 30 pm

Adjust the system time to 4:34 pm; use today's date:

    date 1634

The following command, which illustrates the use of date -s, lets you see a text representation of the date of the last entry in the /usr/adm/syslog file (in this file, the first column of each record is the (long) time in seconds since the Epoch):

Input:
date -s `tail -n1 /usr/adm/syslog | \
cut -f1 -d ' '`
Output:
Wed Apr 15 14:25:49 EDT 1997

For more information, see the cut, logger, and tail utilities.

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 QNX'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 QNX time.

You can specify the format and content of the displayed date and time with the +format option. The format is composed of ASCII character and field descriptors, 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 (see the following table). All other characters are copied to the output without change. To display a "%" character, encode it as %%. The date utility always terminates its output with a newline character.

Field descriptors:


Descriptor:Will be replaced by:
%a Locale's abbreviated weekday name.
%A Locale's full weekday name.
%b Locale's abbreviated month name.
%B Locale's full month name.
%c Locale's appropriate date and time representation.
%d Day of the month as a decimal number (01-31).
%D Date in the format mm/dd/yy.
%h A synonym for %b.
%H Hour (24-hour clock) as a decimal number (00-23).
%I Hour (12-hour clock) as a decimal number (01-12).
%j Day of the year as a decimal number (001-366).
%m Month as a decimal number (01-12).
%M Minute as a decimal number (00-59).
%n Insert a newline character.
%p Locale's equivalent of either am or pm.
%r 12-Hour clock time (01-12) using the AM/PM notation in the format HH:MM:SS AM or HH:MM:SS PM
%S Seconds as a decimal number (00-61). The range of values for %S extends from 0 to 61 seconds to accommodate the occasional leap second or double leap second.
%t Insert a tab character.
%T 24-Hour clock time (00-23) in the format HH:MM:SS.
%U Week number of the year (Sunday as the first day of the week) as a decimal number (00-53).
%w Weekday as a decimal number (0 (Sunday)-6).
%W Week number of the year (Monday as the first day of the week) as a decimal number (00-53).
%x Locale's appropriate date representation.
%X Locale's appropriate time representation.
%y Year without century as a decimal number (00-99).
%Y Year with century as a decimal number.
%Z Time zone name, or no characters if no time zone can be determined.

Setting the date

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

If an adjustment needs to be made, you usually first set the date to the correct setting using date, then run rtc -shw to copy the QNX system time to the battery backed-up hardware clock (on an IBM AT or PS/2).

The date utility recognizes three formats for setting the time:

Format 1:
[[[CC]YY]MM]DD]hhmm[.SS]
Format 2:
MMDDhhmm[YY]
Format 3:
DD [Month [[CC]YY [hh [mm [SS]]]]] [am|pm]

Where:

CC
the century (e.g. 19 if the year is 1997)
YY
the year modulo 100 (e.g. 97 if the year is 1997)
MM
the numerical month of the year (01 for January, 02 for February, etc.)
Month
either the numerical month (1, 2,...12) or the standard English abbreviation for the month (jan, feb,...dec)
DD
the day of the month
hh
the hour of the day
mm
the minute of the hour
SS
the seconds of the minute
am|pm
literally am or pm; can be combined with hour values less than 13 if you don't want a 24-hour clock

Format 1 is compatible with the touch utility. Since each field is two digits, you must specify a leading 0 for single-digit numbers. You should find this format particularly useful for adjusting the time of day, since its minimal form is just hhmm (hour and minute).

Format 2 follows the UNIX System V date conventions. It's similar to the Format 1, with the month and day specified, but the year is optional at the end of the specification instead of the beginning. If there's a dot (.) in the date, date will assume the date is Format 1 instead of Format 2. The date utility also differentiates between MMDDhhmmYY (Format 2) and YYMMDDhhmm (Format 1) by the value of the first pair of digits. The years 00-12 are before the Epoch. Therefore, if the first pair of digits is in that range, the date will be treated as it is in Format 1.

Format 3 follows the date convention used in QNX 4.00 and earlier. This format is assumed if there's more than one operand (the other two formats consist of a single string of digits), or if there's just one number that's two or less digits in length.

Exit status:

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

Environment variables:

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

See also:

Caveats:

Some field descriptors are of unspecified format when not in the POSIX locale. As a result, parsing the output of date may be difficult in other locales.