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