xref: /freebsd/bin/date/date.1 (revision 0de89efe5c443f213c7ea28773ef2dc6cf3af2ed)
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: date.1,v 1.20 1997/10/03 12:49:28 danny Exp $
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 Fl v Ar [+|-]val[ymwdHM]
52.Ar ...
53.Op Fl f Ar fmt Ar date | [[[[yy]mm]dd]HH]MM[\&.ss]
54.Sh DESCRIPTION
55.Nm
56displays the current date and time when invoked without arguments.
57Providing arguments will format the date and time in a user-defined
58way or set the date.
59Only the superuser may set the date.
60.Pp
61The options are as follows:
62.Bl -tag -width Ds
63.It Fl d
64Set the kernel's value for daylight savings time.
65If
66.Ar dst
67is non-zero, future calls
68to
69.Xr gettimeofday 2
70will return a non-zero
71.Ql tz_dsttime  .
72.It Fl f
73Use
74.Ar fmt
75as the format string to parse the date provided rather than using
76the default
77.Ar [[[[yy]mm]dd]HH]MM[.ss]
78format.  Parsing is done using
79.Xr strptime 3 .
80.It Fl n
81The utility
82.Xr timed 8
83is used to synchronize the clocks on groups of machines.
84By default, if
85.Xr timed
86is running,
87.Nm date
88will set the time on all of the machines in the local group.
89The
90.Fl n
91option stops
92.Nm date
93from setting the time for other than the current machine.
94.It Fl r
95Print out the date and time in
96.Ar seconds
97from the Epoch.
98.It Fl t
99Set the kernel's value for minutes west of
100.Tn GMT .
101.Ar Minutes_west
102specifies the number of minutes returned in
103.Ql tz_minuteswest
104by future calls to
105.Xr gettimeofday 2 .
106.It Fl u
107Display or set the date in
108.Tn UCT
109(universal) time.
110.It Fl v
111Adjust the minute, hour, month day, week day, month or year according to
112.Ar val .
113If
114.Ar val
115is preceeded with a plus or minus sign, the date is adjusted forwards
116or backwards according to the remaining string, otherwise the relevant
117part of the date is set.  The date can be adjusted as many times as
118required using these flags.  Flags are processed in the order given.
119.Pp
120Minutes are in the range 0-59, hours are in the range 1-12, month days
121are in the range 1-31, week days are in the range 0-6 (sun-sat), months
122are in the range 1-12 (jan-dec) and years are in the range 80-38 or
1231980-2038.
124.Pp
125If
126.Ar val
127is numeric, one of either
128.Ar y ,
129.Ar m ,
130.Ar w ,
131.Ar d ,
132.Ar H
133or
134.Ar M
135must be used to specify which part of the date is to be adjusted.
136.Pp
137The week day or month may be specified using a name rather than a
138number.  If a name is used with the plus (or minus) sign, the date
139will be put forwards (or backwards) to the next (previous) date that
140matches the given week day or month.  This will not adjust the date
141if the given week day or month is the same as the current one.
142.Pp
143Refer to the examples below for further details.
144.El
145.Pp
146An operand with a leading plus (``+'') sign signals a user-defined format
147string which specifies the format in which to display the date and time.
148The format string may contain any of the conversion specifications described
149in the
150.Xr strftime 3
151manual page, as well as any arbitrary text.
152A <newline> character is always output after the characters specified by
153the format string.
154The format string for the default display is:
155.Bd -literal -offset indent
156``+%+''
157.Ed
158.Pp
159If an operand does not have a leading plus sign, it is interpreted as
160a value for setting the system's notion of the current date and time.
161The canonical representation for setting the date and time is:
162.Pp
163.Bl -tag -width Ds -compact -offset indent
164.It Ar yy
165Year in abbreviated form (e.g. 89 for 1989, 06 for 2006).
166.It Ar mm
167Numeric month.
168A number from 1 to 12.
169.It Ar dd
170Day, a number from 1 to 31.
171.It Ar HH
172Hour, a number from 0 to 23.
173.It Ar MM
174Minutes, a number from 0 to 59.
175.It Ar .ss
176Seconds, a number from 0 to 61 (59 plus a maximum of two leap seconds).
177.El
178.Pp
179Everything but the minutes is optional.
180.Pp
181Time changes for Daylight Saving and Standard time and leap seconds
182and years are handled automatically.
183.Sh EXAMPLES
184The command:
185.Bd -literal -offset indent
186date "+DATE: 19%y-%m-%d%nTIME: %H:%M:%S"
187.Ed
188.Pp
189will display:
190.Bd -literal -offset indent
191DATE: 1987-11-21
192TIME: 13:36:16
193.Ed
194.Pp
195The command:
196.Bd -literal -offset indent
197date -v1m -v+1y
198.Ed
199.Pp
200will display:
201.Bd -literal -offset indent
202Sun Jan  4 03:15:24 GMT 1998
203.Ed
204.Pp
205(where it is currently Mon Aug  4 04:15:24 BST 1997).
206.Pp
207The command:
208.Bd -literal -offset indent
209date -v1d -v3m -v0y -v-1d
210.Ed
211.Pp
212will display the last day of February in the year 2000:
213.Bd -literal -offset indent
214Tue Feb 29 03:18:00 GMT 2000
215.Ed
216.Pp
217The command:
218.Bd -literal -offset indent
219date -v1d -v+1m -v-1d -v-fri
220.Ed
221.Pp
222will display the last friday of the month:
223.Bd -literal -offset indent
224Fri Aug 29 04:31:11 BST 1997
225.Ed
226.Pp
227(where it is currently Mon Aug  4 04:31:11 BST 1997).
228.Pp
229The command:
230.Bd -literal -offset indent
231date 8506131627
232.Ed
233.Pp
234sets the date to
235.Dq Li "June 13, 1985, 4:27 PM" .
236.Pp
237The command:
238.Bd -literal -offset indent
239date 1432
240.Ed
241.Pp
242sets the time to
243.Li "2:32 PM" ,
244without modifying the date.
245.Sh ENVIRONMENT VARIABLES
246The execution of
247.Nm
248is affected by the following environment variables:
249.Bl -tag -width Ds
250.It Ev TZ
251The timezone to use when displaying dates.
252The normal format is a pathname relative to
253.Dq Pa /usr/share/zoneinfo .
254For example, the command
255.Dq TZ=America/Los_Angeles date
256displays the current time in California.
257See
258.Xr environ 7
259for more information.
260.El
261.Sh FILES
262.Bl -tag -width /var/log/messages -compact
263.It Pa /var/log/wtmp
264A record of date resets and time changes.
265.It Pa /var/log/messages
266A record of the user setting the time.
267.El
268.Sh SEE ALSO
269.Xr gettimeofday 2 ,
270.Xr strftime 3 ,
271.Xr strptime 3 ,
272.Xr utmp 5 ,
273.Xr timed 8
274.Rs
275.%T "TSP: The Time Synchronization Protocol for UNIX 4.3BSD"
276.%A R. Gusella
277.%A S. Zatti
278.Re
279.Sh DIAGNOSTICS
280Exit status is 0 on success, 1 if unable to set the date, and 2
281if able to set the local date, but unable to set it globally.
282.Pp
283Occasionally, when
284.Xr timed
285synchronizes the time on many hosts, the setting of a new time value may
286require more than a few seconds.
287On these occasions,
288.Nm date
289prints:
290.Ql Network time being set .
291The message
292.Ql Communication error with timed
293occurs when the communication
294between
295.Nm date
296and
297.Xr timed
298fails.
299.Sh BUGS
300The system attempts to keep the date in a format closely compatible
301with
302.Tn VMS .
303.Tn VMS ,
304however, uses local time (rather than
305.Tn GMT )
306and does not understand daylight-savings time.
307Thus, if you use both
308.Tn UNIX
309and
310.Tn VMS ,
311.Tn VMS
312will be running on
313.Tn GMT .
314.Sh STANDARDS
315The
316.Nm date
317command is expected to be compatible with
318.St -p1003.2 .
319.Sh HISTORY
320A
321.Nm
322command appeared in
323.At v1 .
324