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