| Skip Navigation Links | |
| Exit Print View | |
![]() | man pages section 1: User Commands Oracle Solaris 11 Information Library |
- write the date and time
/usr/bin/date [-u] [+format]
/usr/bin/date [-a [-]sss.fff]
/usr/bin/date [-u] [ [mmdd]HHMM |mmddHHMM [cc]yy] [.SS]
/usr/xpg4/bin/date [-u] [+format]
/usr/xpg4/bin/date [-a [-]sss.fff]
/usr/xpg4/bin/date [-u] [ [mmdd]HHMM |mmddHHMM [cc]yy] [.SS]
Thedate utility writes the date and time to standard output or attemptsto set the system date and time. By default, the current date andtime is written.
Specifications of native language translations of month and weekday names are supported. Themonth and weekday names used for a language are based on the localespecified by the environment variableLC_TIME. Seeenviron(5).
The following is the default form for theC locale:
%a %b %e %T %Z %Y
For example,
Fri Dec 23 10:10:42 EST 1988
The following options are supported:
Slowly adjust the time bysss.fff seconds (fff represents fractions of a second). This adjustment can be positive or negative. The system's clock is sped up or slowed down until it has drifted by the number of seconds specified. Only the super-user may adjust the time.
Display (or set) the date in Greenwich Mean Time (GMT—universal time), bypassing the normal conversion to (or from) local time.
The following operands are supported:
If the argument begins with+, the output ofdate is the result of passingformat and the current time tostrftime().date uses the conversion specifications listed on thestrftime(3C) manual page, with the conversion specification for%C determined by whether/usr/bin/date or/usr/xpg4/bin/date is used:
Locale's date and time representation. This is the default output fordate.
Century (a year divided by 100 and truncated to an integer) as a decimal number [00-99].
Additionally, date supports%N which represents nanosecond portion of the current time since Epoch (00:00:00 UTC, January 1, 1970) as a decimal number [000000000-999999999]. The conversion specification accepts an optional flag character, an optional field width, or both as specified instrftime() with a difference that, if a field width specified is less than nine, the actual date output contains only the specified amount of digits of the nanoseconds from left.
The string is always terminated with a NEWLINE. An argument containing blanks must be quoted; see theEXAMPLES section.
Month number
Day number in the month
Hour number (24 hour system)
Minute number
Second number
Century (a year divided by 100 and truncated to an integer) as a decimal number [00-99]. For example,cc is19 for the year 1988 and20 for the year 2007.
Last two digits of the year number. If century (cc) is not specified, then values in the range69–99 shall refer to years 1969 to 1999 inclusive, and values in the range00–68 shall refer to years 2000 to 2068, inclusive.
The month, day, year number, and century may be omitted; the current valuesare applied as defaults. For example, the following entry:
example%date 10080045
sets the date to Oct 8, 12:45 a.m. The current year isthe default because no year is supplied. The system operates in GMT.datetakes care of the conversion to and from local standard and daylight time.Only the super-user may change the date. After successfully setting the date and time,date displays the new date according to the default format. Thedate commandusesTZ to determine the correct time zone information; seeenviron(5).
Example 1 Generating Output
The following command:
example%date '+DATE: %m/%d/%y%nTIME:%H:%M:%S'
generates as output
DATE: 08/01/76TIME: 14:45:05
Example 2 Setting the Current Time
The following command sets the current time to12:34:56:
example#date 1234.56
Example 3 Setting Another Time and Date in Greenwich Mean Time
The following command sets the date to January 1st, 12:30 am, 2000:
example#date -u 010100302000
This is displayed as:
Thu Jan 01 00:30:00 GMT 2000
Seeenviron(5) for descriptions of the following environment variables that affect the execution ofdate:LANG,LC_ALL,LC_CTYPE,LC_TIME,LC_MESSAGES, andNLSPATH.
Determine the timezone in which the time and date are written, unless the-u option is specified. If theTZ variable is not set and the-u is not specified, the system default timezone is used.
The following exit values are returned:
Successful completion.
An error occurred.
Seeattributes(5) for descriptions of the following attributes:
|
|
strftime(3C),attributes(5),environ(5),standards(5)
You are not the super-user and you tried to change the date.
The date set is syntactically incorrect.
If you attempt to set the current date to one of thedates that the standard and alternate time zones change (for example, the datethat daylight time is starting or ending), and you attempt to set thetime to a time in the interval between the end of standard timeand the beginning of the alternate time (or the end of the alternatetime and the beginning of standard time), the results are unpredictable.
Using thedate command from within windowing environments to change the date canlead to unpredictable results and is unsafe. It can also be unsafe inthe multi-user mode, that is, outside of a windowing system, if the dateis changed rapidly back and forth. The recommended method of changing the dateis 'date-a'.
Setting the system time or allowing the system time to progress beyond03:14:07 UTC Jan 19, 2038 is not supported on Solaris.
Copyright © 2011, Oracle and/or its affiliates. All rights reserved.Legal Notices | ![]() ![]() |