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