xref: /openbsd/bin/date/date.1 (revision 4bdff4be)
1.\"	$OpenBSD: date.1,v 1.72 2021/04/29 00:47:53 deraadt Exp $
2.\"	$NetBSD: date.1,v 1.12 1996/03/12 04:32:37 phil Exp $
3.\"
4.\" Copyright (c) 1980, 1990, 1993
5.\"	The Regents of the University of California.  All rights reserved.
6.\"
7.\" This code is derived from software contributed to Berkeley by
8.\" the Institute of Electrical and Electronics Engineers, Inc.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\"    notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\"    notice, this list of conditions and the following disclaimer in the
17.\"    documentation and/or other materials provided with the distribution.
18.\" 3. Neither the name of the University nor the names of its contributors
19.\"    may be used to endorse or promote products derived from this software
20.\"    without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.\"     @(#)date.1	8.3 (Berkeley) 4/28/95
35.\"
36.Dd $Mdocdate: April 29 2021 $
37.Dt DATE 1
38.Os
39.Sh NAME
40.Nm date
41.Nd display or set date and time
42.Sh SYNOPSIS
43.Nm date
44.Op Fl aju
45.Op Fl f Ar pformat
46.Op Fl r Ar seconds
47.Op Fl z Ar output_zone
48.Op Cm + Ns Ar format
49.Sm off
50.Oo Oo Oo Oo Oo Oo
51.Ar cc Oc
52.Ar yy Oc
53.Ar mm Oc
54.Ar dd Oc
55.Ar HH Oc
56.Ar MM
57.Op . Ar SS
58.Oc
59.Sm on
60.Sh DESCRIPTION
61When invoked without arguments, the
62.Nm
63utility displays the current date and time.
64Otherwise, depending on the options specified,
65.Nm
66will set the date and time or print it in a user-defined way.
67.Pp
68Changing the system date has some risks, as described in
69.Xr settimeofday 2 .
70Only the superuser may change the date.
71.Pp
72The options are as follows:
73.Bl -tag -width Ds
74.It Fl a
75Use the
76.Xr adjtime 2
77call to gradually skew the local time to the
78desired time rather than just hopping.
79.It Fl f Ar pformat
80Parse the specified time using
81.Xr strptime 3
82with a format string of
83.Ar pformat .
84.It Fl j
85Parse the provided date and time and display the result without changing
86the clock.
87.It Fl r Ar seconds
88Print out (in specified format) the date and time represented by
89.Ar seconds
90from the Epoch.
91.It Fl u
92Display or set the date in UTC (Coordinated Universal) time.
93.It Fl z Ar output_zone
94Just before printing the time, change to the specified timezone;
95see the description of
96.Ev TZ
97below.
98This can be used with
99.Fl j
100to easily convert time specifications from one zone to another.
101.El
102.Pp
103An operand with a leading plus sign
104.Pq Sq +
105signals a user-defined format
106string which specifies the format in which to display the date and time.
107The format string may contain any of the conversion specifications described
108in the
109.Xr strftime 3
110manual page, as well as any arbitrary text.
111A newline
112.Pq Ql \en
113character is always output after the characters specified by
114the format string.
115The format string for the default display is:
116.Bd -literal -offset indent
117%a %b %e %H:%M:%S %Z %Y
118.Ed
119.Pp
120If an operand does not have a leading plus sign, it is interpreted as
121a value for setting the system's notion of the current date and time.
122The canonical representation for setting the date and time is:
123.Pp
124.Bl -tag -width Ds -compact -offset indent
125.It Ar ccyy
126Year.
127If yy is specified, but cc is not,
128a value for yy between 69 and 99 results in a cc value of 19.
129Otherwise, a cc value of 20 is used.
130.It Ar mm
131Month:
132a number from 1 to 12.
133.It Ar dd
134Day:
135a number from 1 to 31.
136.It Ar HH
137Hour:
138a number from 0 to 23.
139.It Ar MM
140Minute:
141a number from 0 to 59.
142.It Ar SS
143Second:
144a number from 0 to 60
145(permitting a leap second),
146preceded by a period.
147.El
148.Pp
149Everything but the minute is optional.
150.Pp
151Time changes for Daylight Saving Time, standard time, leap seconds,
152and leap years are handled automatically.
153.Sh ENVIRONMENT
154.Bl -tag -width Ds
155.It Ev TZ
156The time zone to use when parsing or displaying dates.
157It is normally specified as a pathname relative to
158.Pa /usr/share/zoneinfo ,
159though see
160.Xr tzset 3
161for more information.
162If this variable is not set, the time zone is determined based on
163.Pa /etc/localtime ,
164which the administrator adjusts using
165the
166.Fl l
167option of
168.Xr zic 8 .
169.El
170.Sh FILES
171.Bl -tag -width /var/log/messages -compact
172.It Pa /var/log/wtmp
173record of date resets and time changes
174.It Pa /var/log/messages
175record of the user setting the time
176.El
177.Sh EXIT STATUS
178.Ex -std
179.Sh EXAMPLES
180Display the date using the specified format string:
181.Bd -literal -offset indent
182$ date "+DATE: %Y-%m-%d%nTIME: %H:%M:%S"
183DATE: 1987-11-21
184TIME: 13:36:16
185.Ed
186.Pp
187Set the date to
188June 13, 1985, 4:27 PM:
189.Pp
190.Dl # date 198506131627
191.Pp
192Set the time to
1932:32 PM,
194without modifying the date:
195.Pp
196.Dl # date 1432
197.Pp
198If the mailing list server located in California
199is being taken offline at 5:45 AM,
200work out what time it will be locally, here in Tokyo:
201.Pp
202.Dl $ TZ=America/Los_Angeles date -j -z Asia/Tokyo 0545
203.Sh SEE ALSO
204.Xr adjtime 2 ,
205.Xr gettimeofday 2 ,
206.Xr strftime 3 ,
207.Xr utmp 5 ,
208.Xr ntpd 8 ,
209.Xr rdate 8
210.Sh STANDARDS
211The
212.Nm
213utility is compliant with the
214.St -p1003.1-2008
215specification.
216.Pp
217The flags
218.Op Fl afjrz ,
219as well as the conversion specifiers
220.Ql \&%F ,
221.Ql \&%G ,
222.Ql \&%g ,
223.Ql \&%k ,
224.Ql \&%l ,
225.Ql \&%R ,
226.Ql \&%s ,
227.Ql \&%v ,
228and
229.Ql \&%+ ,
230are extensions to that specification.
231.Pp
232This implementation requires the traditional
233.Bx
234date format,
235[[[[[cc]yy]mm]dd]HH]MM[.SS],
236which differs from the
237X/Open System Interfaces option of the
238.St -p1003.1-2008
239specification.
240.Sh HISTORY
241A
242.Nm
243command appeared in
244.At v1 .
245