xref: /freebsd/bin/date/date.1 (revision 17ee9d00bc1ae1e598c38f25826f861e4bc6c3ce)
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.2 (Berkeley) 11/17/93
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 Date
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.
108The format string for the default display is:
109.Bd -literal -offset indent
110``%a %b %e %H:%M:%S %Z %Y%n''.
111.Ed
112.Pp
113If an operand does not have a leading plus sign, it is interpreted as
114a value for setting the system's notion of the current date and time.
115The canonical representation for setting the date and time is:
116.Pp
117.Bl -tag -width Ds -compact -offset indent
118.It Ar yy
119Year in abbreviated form (.e.g 89 for 1989).
120.It Ar mm
121Numeric month.
122A number from 1 to 12.
123.It Ar dd
124Day, a number from 1 to 31.
125.It Ar hh
126Hour, a number from 0 to 23.
127.It Ar mm
128Minutes, a number from 0 to 59.
129.It Ar .ss
130Seconds, a number from 0 to 61 (59 plus a a maximum of two leap seconds).
131.El
132.Pp
133Everything but the minutes is optional.
134.Pp
135Time changes for Daylight Saving and Standard time and leap seconds
136and years are handled automatically.
137.Sh EXAMPLES
138The command:
139.Bd -literal -offset indent
140date ``+DATE: %m/%d/%y%nTIME: %H:%M:%S%n''
141.Ed
142.Pp
143will display:
144.Bd -literal -offset indent
145DATE: 11/21/87
146TIME: 13:36:16
147.Ed
148.Pp
149The command:
150.Bd -literal -offset indent
151date 8506131627
152.Ed
153.Pp
154sets the date to
155.Dq Li "June 13, 1985, 4:27 PM" .
156.Pp
157The command:
158.Bd -literal -offset indent
159date 1432
160.Ed
161.Pp
162sets the time to
163.Li "2:32 PM" ,
164without modifying the date.
165.Sh ENVIRONMENTAL VARIABLES
166The following environment variables affect the execution of
167.Nm date :
168.Bl -tag -width Ds
169.It Ev TZ
170The timezone to use when displaying dates.
171See
172.Xr environ 7
173for more information.
174.El
175.Sh FILES
176.Bl -tag -width /var/log/messages -compact
177.It Pa /var/log/wtmp
178A record of date resets and time changes.
179.It Pa /var/log/messages
180A record of the user setting the time.
181.El
182.Sh SEE ALSO
183.Xr gettimeofday 2 ,
184.Xr strftime 3 ,
185.Xr utmp 5 ,
186.Xr timed 8
187.Rs
188.%T "TSP: The Time Synchronization Protocol for UNIX 4.3BSD"
189.%A R. Gusella
190.%A S. Zatti
191.Re
192.Sh DIAGNOSTICS
193Exit status is 0 on success, 1 if unable to set the date, and 2
194if able to set the local date, but unable to set it globally.
195.Pp
196Occasionally, when
197.Xr timed
198synchronizes the time on many hosts, the setting of a new time value may
199require more than a few seconds.
200On these occasions,
201.Nm date
202prints:
203.Ql Network time being set .
204The message
205.Ql Communication error with timed
206occurs when the communication
207between
208.Nm date
209and
210.Xr timed
211fails.
212.Sh BUGS
213The system attempts to keep the date in a format closely compatible
214with
215.Tn VMS .
216.Tn VMS ,
217however, uses local time (rather than
218.Tn GMT )
219and does not understand daylight-savings time.
220Thus, if you use both
221.Tn UNIX
222and
223.Tn VMS ,
224.Tn VMS
225will be running on
226.Tn GMT .
227.Sh STANDARDS
228The
229.Nm date
230command is expected to be compatible with
231.St -p1003.2 .
232