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