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