xref: /netbsd-src/bin/date/date.1 (revision 3b01aba77a7a698587faaae455bbfe740923c1f5)
1.\"	$NetBSD: date.1,v 1.27 2001/03/09 15:16:49 hubertf 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. All advertising materials mentioning features or use of this software
18.\"    must display the following acknowledgement:
19.\"	This product includes software developed by the University of
20.\"	California, Berkeley and its contributors.
21.\" 4. Neither the name of the University nor the names of its contributors
22.\"    may be used to endorse or promote products derived from this software
23.\"    without specific prior written permission.
24.\"
25.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35.\" SUCH DAMAGE.
36.\"
37.\"     @(#)date.1	8.3 (Berkeley) 4/28/95
38.\"
39.Dd March 8, 2001
40.Dt DATE 1
41.Os
42.Sh NAME
43.Nm date
44.Nd display or set date and time
45.Sh SYNOPSIS
46.Nm
47.Op Fl nu
48.Op Fl r Ar seconds
49.Op Cm + Ns Ar format
50.Nm ""
51.Sm off
52.Oo Oo Oo Oo Oo
53.Ar cc Oc
54.Ar yy Oc
55.Ar mm Oc
56.Ar dd Oc
57.Ar hh Oc Ar mm Oo
58.Li \&. Ar ss Oc
59.Sm on
60.Sh DESCRIPTION
61.Nm
62displays the current date and time when invoked without arguments.
63Providing arguments will format the date and time in a user-defined
64way or set the date.
65Only the superuser may set the date.
66.Pp
67The options are as follows:
68.Bl -tag -width Ds
69.It Fl n
70The utility
71.Xr timed 8
72is used to synchronize the clocks on groups of machines.
73By default, if
74timed
75is running,
76.Nm
77will set the time on all of the machines in the local group.
78The
79.Fl n
80option stops
81.Nm
82from setting the time for other than the current machine.
83.It Fl r
84Print out the date and time that is
85.Ar seconds
86from the Epoch.
87.It Fl u
88Display or set the date in
89.Tn UTC
90(universal) time.
91.El
92.Pp
93An operand with a leading plus
94.Pq Cm +
95sign signals a user-defined format
96string which specifies the format in which to display the date and time.
97The format string may contain any of the conversion specifications described
98in the
99.Xr strftime 3
100manual page, as well as any arbitrary text.
101A <newline> character is always output after the characters specified by
102the format string.
103The format string for the default display is:
104.Bd -literal -offset indent
105%a %b %e %H:%M:%S %Z %Y
106.Ed
107.Pp
108If an operand does not have a leading plus sign, it is interpreted as
109a value for setting the system's notion of the current date and time.
110The canonical representation for setting the date and time is:
111.Pp
112.Bl -tag -width Ds -compact -offset indent
113.It Ar cc
114The first two digits of the year (the century).
115.It Ar yy
116The second two digits of the year.  If
117.Ar yy
118is specified, but
119.Ar cc
120is not, a value for
121.Ar yy
122between 69 and 99 results in a
123.Ar cc
124value of 19.  Otherwise, a
125.Ar cc
126value of 20 is used.
127.It Ar mm
128The month of the year, from 01 to 12.
129.It Ar dd
130The day of the month, from 01 to 31.
131.It Ar hh
132The hour of the day, from 00 to 23.
133.It Ar mm
134The minute of the hour, from 00 to 59.
135.It Ar ss
136The second of the minute, from 00 to 61.
137.El
138.Pp
139Everything but the minutes is optional.
140.Pp
141Time changes for Daylight Saving and Standard time and leap seconds
142and years are handled automatically.
143.Sh EXAMPLES
144The command:
145.Bd -literal -offset indent
146date '+DATE: %m/%d/%y%nTIME: %H:%M:%S'
147.Ed
148.Pp
149will display:
150.Bd -literal -offset indent
151DATE: 11/21/87
152TIME: 13:36:16
153.Ed
154.Pp
155The command:
156.Bd -literal -offset indent
157date 8506131627
158.Ed
159.Pp
160sets the date to
161.Dq Li "June 13, 1985, 4:27 PM" .
162.Pp
163The command:
164.Bd -literal -offset indent
165date 1432
166.Ed
167.Pp
168sets the time to
169.Li "2:32 PM" ,
170without modifying the date.
171.Sh ENVIRONMENT VARIABLES
172The following environment variables affect the execution of
173.Nm "" :
174.Bl -tag -width iTZ
175.It Ev TZ
176The timezone to use when displaying dates.
177See
178.Xr environ 7
179for more information.
180.El
181.Sh FILES
182.Bl -tag -width /var/log/messages -compact
183.It Pa /etc/localtime
184Symlink pointing to system's default timezone information file in
185.Pa /usr/share/zoneinfo
186directory.
187.It Pa /var/log/wtmp
188A record of date resets and time changes.
189.It Pa /var/log/messages
190A record of the user setting the time.
191.El
192.Sh SEE ALSO
193.Xr gettimeofday 2 ,
194.Xr settimeofday 2 ,
195.Xr strftime 3 ,
196.Xr utmp 5 ,
197.Xr timed 8
198.Rs
199.%T "TSP: The Time Synchronization Protocol for UNIX 4.3BSD"
200.%A R. Gusella
201.%A S. Zatti
202.Re
203.Sh DIAGNOSTICS
204Exit status is 0 on success, 1 if unable to set the date, and 2
205if able to set the local date, but unable to set it globally.
206.Pp
207Occasionally, when
208.Xr timed 8
209synchronizes the time on many hosts, the setting of a new time value may
210require more than a few seconds.
211On these occasions,
212.Nm
213prints:
214.Ql Network time being set .
215The message
216.Ql Communication error with timed
217occurs when the communication
218between
219.Nm
220and
221timed
222fails.
223.Sh STANDARDS
224The
225.Nm
226utility is expected to be compatible with
227.St -p1003.2 .
228