xref: /freebsd/bin/date/date.1 (revision df7f5d4de4592a8948a25ce01e5bddfbb7ce39dc)
1.\" Copyright (c) 1980, 1990, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" This code is derived from software contributed to Berkeley by
5.\" the Institute of Electrical and Electronics Engineers, Inc.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\" 3. All advertising materials mentioning features or use of this software
16.\"    must display the following acknowledgement:
17.\"	This product includes software developed by the University of
18.\"	California, Berkeley and its contributors.
19.\" 4. Neither the name of the University nor the names of its contributors
20.\"    may be used to endorse or promote products derived from this software
21.\"    without specific prior written permission.
22.\"
23.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33.\" SUCH DAMAGE.
34.\"
35.\"     @(#)date.1	8.3 (Berkeley) 4/28/95
36.\"	$Id$
37.\"
38.Dd November 17, 1993
39.Dt DATE 1
40.Os
41.Sh NAME
42.Nm date
43.Nd display or set date and time
44.Sh SYNOPSIS
45.Nm date
46.Op Fl d Ar dst
47.Op Fl r Ar seconds
48.Op Fl t Ar minutes_west
49.Op Fl nu
50.Op Cm + Ns Ar format
51.Op [yy[mm[dd[hh]]]]mm[\&.ss]
52.Sh DESCRIPTION
53.Nm
54displays the current date and time when invoked without arguments.
55Providing arguments will format the date and time in a user-defined
56way or set the date.
57Only the superuser may set the date.
58.Pp
59The options are as follows:
60.Bl -tag -width Ds
61.It Fl d
62Set the kernel's value for daylight savings time.
63If
64.Ar dst
65is non-zero, future calls
66to
67.Xr gettimeofday 2
68will return a non-zero
69.Ql tz_dsttime  .
70.It Fl n
71The utility
72.Xr timed 8
73is used to synchronize the clocks on groups of machines.
74By default, if
75.Xr timed
76is running,
77.Nm date
78will set the time on all of the machines in the local group.
79The
80.Fl n
81option stops
82.Nm date
83from setting the time for other than the current machine.
84.It Fl r
85Print out the date and time in
86.Ar seconds
87from the Epoch.
88.It Fl t
89Set the kernel's value for minutes west of
90.Tn GMT .
91.Ar Minutes_west
92specifies the number of minutes returned in
93.Ql tz_minuteswest
94by future calls to
95.Xr gettimeofday 2 .
96.It Fl u
97Display or set the date in
98.Tn UCT
99(universal) time.
100.El
101.Pp
102An operand with a leading plus (``+'') sign signals a user-defined format
103string which specifies the format in which to display the date and time.
104The format string may contain any of the conversion specifications described
105in the
106.Xr strftime 3
107manual page, as well as any arbitrary text.
108A <newline> character is always output after the characters specified by
109the format string.
110The format string for the default display is:
111.Bd -literal -offset indent
112``+%+''
113.Ed
114.Pp
115If an operand does not have a leading plus sign, it is interpreted as
116a value for setting the system's notion of the current date and time.
117The canonical representation for setting the date and time is:
118.Pp
119.Bl -tag -width Ds -compact -offset indent
120.It Ar yy
121Year in abbreviated form (.e.g 89 for 1989).
122.It Ar mm
123Numeric month.
124A number from 1 to 12.
125.It Ar dd
126Day, a number from 1 to 31.
127.It Ar hh
128Hour, a number from 0 to 23.
129.It Ar mm
130Minutes, a number from 0 to 59.
131.It Ar .ss
132Seconds, a number from 0 to 61 (59 plus a maximum of two leap seconds).
133.El
134.Pp
135Everything but the minutes is optional.
136.Pp
137Time changes for Daylight Saving and Standard time and leap seconds
138and years are handled automatically.
139.Sh EXAMPLES
140The command:
141.Bd -literal -offset indent
142date ``+DATE: %m/%d/%y%nTIME: %H:%M:%S''
143.Ed
144.Pp
145will display:
146.Bd -literal -offset indent
147DATE: 11/21/87
148TIME: 13:36:16
149.Ed
150.Pp
151The command:
152.Bd -literal -offset indent
153date 8506131627
154.Ed
155.Pp
156sets the date to
157.Dq Li "June 13, 1985, 4:27 PM" .
158.Pp
159The command:
160.Bd -literal -offset indent
161date 1432
162.Ed
163.Pp
164sets the time to
165.Li "2:32 PM" ,
166without modifying the date.
167.Sh ENVIRONMENT VARIABLES
168The execution of
169.Nm
170is affected by the following evironment variables:
171.Bl -tag -width Ds
172.It Ev TZ
173The timezone to use when displaying dates.
174See
175.Xr environ 7
176for more information.
177.El
178.Sh FILES
179.Bl -tag -width /var/log/messages -compact
180.It Pa /var/log/wtmp
181A record of date resets and time changes.
182.It Pa /var/log/messages
183A record of the user setting the time.
184.El
185.Sh SEE ALSO
186.Xr gettimeofday 2 ,
187.Xr strftime 3 ,
188.Xr utmp 5 ,
189.Xr timed 8
190.Rs
191.%T "TSP: The Time Synchronization Protocol for UNIX 4.3BSD"
192.%A R. Gusella
193.%A S. Zatti
194.Re
195.Sh DIAGNOSTICS
196Exit status is 0 on success, 1 if unable to set the date, and 2
197if able to set the local date, but unable to set it globally.
198.Pp
199Occasionally, when
200.Xr timed
201synchronizes the time on many hosts, the setting of a new time value may
202require more than a few seconds.
203On these occasions,
204.Nm date
205prints:
206.Ql Network time being set .
207The message
208.Ql Communication error with timed
209occurs when the communication
210between
211.Nm date
212and
213.Xr timed
214fails.
215.Sh BUGS
216The system attempts to keep the date in a format closely compatible
217with
218.Tn VMS .
219.Tn VMS ,
220however, uses local time (rather than
221.Tn GMT )
222and does not understand daylight-savings time.
223Thus, if you use both
224.Tn UNIX
225and
226.Tn VMS ,
227.Tn VMS
228will be running on
229.Tn GMT .
230.Sh STANDARDS
231The
232.Nm date
233command is expected to be compatible with
234.St -p1003.2 .
235.Sh HISTORY
236A
237.Nm
238command appeared in
239.At v1 .
240