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