xref: /netbsd-src/bin/date/date.1 (revision 2f62cc9c12bc202c40224f32c879f81443fee079)
1.\"	$NetBSD: date.1,v 1.54 2023/05/31 18:04:00 uwe Exp $
2.\"
3.\" Copyright (c) 1980, 1990, 1993
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" the Institute of Electrical and Electronics Engineers, Inc.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\" 3. Neither the name of the University nor the names of its contributors
18.\"    may be used to endorse or promote products derived from this software
19.\"    without specific prior written permission.
20.\"
21.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31.\" SUCH DAMAGE.
32.\"
33.\"     @(#)date.1	8.3 (Berkeley) 4/28/95
34.\"
35.Dd May 31, 2023
36.Dt DATE 1
37.Os
38.Sh NAME
39.Nm date
40.Nd display or set date and time
41.Sh SYNOPSIS
42.Nm
43.Op Fl ajnRu
44.Op Fl d Ar date
45.Op Fl r Ar seconds
46.Op Cm + Ns Ar format
47.Sm off
48.Oo
49.Oo Oo Oo Oo Oo
50.Ar CC Oc
51.Ar yy Oc
52.Ar mm Oc
53.Ar dd Oc
54.Ar HH Oc
55.Ar MM
56.Op Cm \&. Ar SS
57.Oc
58.Sm on
59.Nm
60.Op Fl ajnRu
61.Fl f Ar input_format
62.Ar new_date
63.Op Cm + Ns Ar format
64.Sh DESCRIPTION
65.Nm
66displays the current date and time when invoked without arguments.
67Providing arguments will format the date and time in a user-defined
68way or set the date.
69Only the superuser may set the date.
70.Pp
71The options are as follows:
72.Bl -tag -width Fl
73.It Fl a
74Use
75.Xr adjtime 2
76to change the local system time slowly,
77maintaining it as a monotonically increasing function.
78.Fl a
79implies
80.Fl n .
81.It Fl d Ar date
82Parse the provided human-described date and time and display the result without
83actually changing the system clock.
84(See
85.Xr parsedate 3
86for examples.)
87.It Fl f Ar input_fmt
88Use
89.Ar input_fmt
90as the format string to parse the
91.Ar new_date
92provided rather than using the default
93.Sm off
94.Oo Oo Oo Oo Oo
95.Ar CC Oc
96.Ar yy Oc
97.Ar mm Oc
98.Ar dd Oc
99.Ar HH Oc
100.Ar MM
101.Op Cm \&. Ar SS
102.Sm on
103format.
104Parsing is done using
105.Xr strptime 3 .
106.It Fl j
107Parse the provided canonical representation of date and time (described below)
108and display the result without actually changing the system clock.
109.It Fl n
110The utility
111.Xr timed 8
112is used to synchronize the clocks on groups of machines.
113By default, if
114.Xr timed 8
115is running,
116.Nm
117will set the time on all of the machines in the local group.
118The
119.Fl n
120option stops
121.Nm
122from setting the time for other than the current machine.
123.It Fl R
124Use a default display format that conforms to the date and time
125specification in RFC 5322 (Internet Message Format).
126.It Fl r Ar seconds
127Print out the date and time that is
128.Ar seconds
129from the Epoch.
130.It Fl u
131Display or set the date in UTC (universal) time.
132.El
133.Pp
134An operand with a leading plus
135.Pq Cm +
136sign signals a user-defined format
137string which specifies the format in which to display the date and time.
138The format string may contain any of the conversion specifications described
139in the
140.Xr strftime 3
141manual page, as well as any arbitrary text.
142A
143.Aq newline
144character is always output after the characters
145specified by the format string.
146The format string for the default display is:
147.Pp
148.Dl %a %b %e %H:%M:%S %Z %Y
149.Pp
150If an operand does not have a leading plus sign, it is interpreted as
151a value for setting the system's notion of the current date and time.
152The canonical representation for setting the date and time is:
153.Pp
154.Bl -tag -width Ds -compact -offset indent
155.It Ar CC
156The first two digits of the year (the century).
157.It Ar yy
158The second two digits of the year.
159If
160.Ar yy
161is specified, but
162.Ar CC
163is not, a value for
164.Ar yy
165between 69 and 99 results in a
166.Ar CC
167value of 19.
168Otherwise, a
169.Ar CC
170value of 20 is used.
171.It Ar mm
172The month of the year, from 01 to 12.
173.It Ar dd
174The day of the month, from 01 to 31.
175.It Ar HH
176The hour of the day, from 00 to 23.
177.It Ar MM
178The minute of the hour, from 00 to 59.
179.It Ar SS
180The second of the minute, from 00 to 60.
181.El
182.Pp
183Everything but the minutes is optional.
184.Pp
185Time changes for Daylight Saving and Standard Time and leap seconds
186and years are handled automatically.
187.Sh ENVIRONMENT
188The following environment variables affect the execution of
189.Nm :
190.Bl -tag -width Ev
191.It Ev TZ
192The timezone to use when displaying dates.
193See
194.Xr environ 7
195for more information.
196.El
197.Sh FILES
198.Bl -tag -width Pa -compact
199.It Pa /etc/localtime
200Symlink pointing to system's default timezone information file in
201.Pa /usr/share/zoneinfo
202directory.
203.It Pa /usr/lib/locale/ Ns Ao Ar L Ac Ns Pa /LC_TIME
204Description of time locale
205.Aq Ar L .
206.It Pa /usr/share/zoneinfo
207Time zone information directory.
208.It Pa /usr/share/zoneinfo/posixrules
209Used with POSIX-style TZ's.
210.It Pa /usr/share/zoneinfo/GMT
211For UTC leap seconds.
212.It Pa /var/log/wtmp
213A record of date resets and time changes.
214.It Pa /var/log/messages
215A record of the user setting the time.
216.El
217.Pp
218If
219.Pa /usr/share/zoneinfo/GMT
220is absent, UTC leap seconds are loaded from
221.Pa /usr/share/zoneinfo/posixrules .
222.Sh EXAMPLES
223The command:
224.Pp
225.Dl date '+DATE: %m/%d/%y%nTIME: %H:%M:%S'
226.Pp
227will display:
228.Bd -literal -offset indent
229DATE: 11/21/87
230TIME: 13:36:16
231.Ed
232.Pp
233The command:
234.Pp
235.Dl date 8506131627
236.Pp
237sets the date to
238.Dq Li "June 13, 1985, 4:27 PM" .
239.Pp
240The command:
241.Pp
242.Dl date 1432
243.Pp
244sets the time to
245.Li "2:32 PM" ,
246without modifying the date.
247.Pp
248The command:
249.Pp
250.Dl date +%s
251.Pp
252prints the current time as seconds since the Epoch.
253.Sh DIAGNOSTICS
254Exit status is 0 on success, 1 if unable to set the date, and 2
255if able to set the local date, but unable to set it globally.
256.Pp
257Occasionally, when
258.Xr timed 8
259synchronizes the time on many hosts, the setting of a new time value may
260require more than a few seconds.
261On these occasions,
262.Nm
263prints:
264.Ql Network time being set .
265The message
266.Ql Communication error with
267.Xr timed 8
268occurs when the communication
269between
270.Nm
271and
272.Xr timed 8
273fails.
274.Sh SEE ALSO
275.Xr adjtime 2 ,
276.Xr gettimeofday 2 ,
277.Xr settimeofday 2 ,
278.Xr parsedate 3 ,
279.Xr strftime 3 ,
280.Xr utmp 5 ,
281.Xr environ 7 ,
282.Xr timed 8
283.Rs
284.%T "TSP: The Time Synchronization Protocol for UNIX 4.3BSD"
285.%A R. Gusella
286.%A S. Zatti
287.Re
288.Sh STANDARDS
289The
290.Nm
291utility is expected to be compatible with
292.St -p1003.2 .
293.Sh HISTORY
294A
295.Nm
296utility appeared in
297.At v1 .
298