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