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.Pq 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 167.Pq Sun-Sat , 168months are in the range 1-12 169.Pq Jan-Dec 170and years are in the range 80-38 or 1980-2038. 171.Pp 172If 173.Ar val 174is numeric, one of either 175.Ar y , 176.Ar m , 177.Ar w , 178.Ar d , 179.Ar H , 180.Ar M 181or 182.Ar S 183must be used to specify which part of the date is to be adjusted. 184.Pp 185The week day or month may be specified using a name rather than a 186number. 187If a name is used with the plus 188.Pq or minus 189sign, the date will be put forwards 190.Pq or backwards 191to the next 192.Pq previous 193date that matches the given week day or month. 194This will not adjust the date, 195if the given week day or month is the same as the current one. 196.Pp 197When a date is adjusted to a specific value or in units greater than hours, 198daylight savings time considerations are ignored. 199Adjustments in units of hours or less honor daylight saving time. 200So, assuming the current date is March 26, 0:30 and that the DST adjustment 201means that the clock goes forward at 01:00 to 02:00, using 202.Fl v No +1H 203will adjust the date to March 26, 2:30. 204Likewise, if the date is October 29, 0:30 and the DST adjustment means that 205the clock goes back at 02:00 to 01:00, using 206.Fl v No +3H 207will be necessary to reach October 29, 2:30. 208.Pp 209When the date is adjusted to a specific value that doesn't actually exist 210.Po 211for example March 26, 1:30 BST 2000 in the Europe/London timezone 212.Pc , 213the date will be silently adjusted forwards in units of one hour until it 214reaches a valid time. 215When the date is adjusted to a specific value that occurs twice 216.Pq for example October 29, 1:30 2000 , 217the resulting timezone will be set so that the date matches the earlier of 218the two times. 219.Pp 220Refer to the examples below for further details. 221.El 222.Pp 223An operand with a leading plus 224.Pq Sq + 225sign signals a user-defined format string 226which specifies the format in which to display the date and time. 227The format string may contain any of the conversion specifications 228described in the 229.Xr strftime 3 230manual page, as well as any arbitrary text. 231A newline 232.Pq Ql \en 233character is always output after the characters specified by 234the format string. 235The format string for the default display is 236.Dq +%+ . 237.Pp 238If an operand does not have a leading plus sign, it is interpreted as 239a value for setting the system's notion of the current date and time. 240The canonical representation for setting the date and time is: 241.Pp 242.Bl -tag -width Ds -compact -offset indent 243.It Ar cc 244Century 245.Pq either 19 or 20 246prepended to the abbreviated year. 247.It Ar yy 248Year in abbreviated form 249.Pq e.g. 89 for 1989, 06 for 2006 . 250.It Ar mm 251Numeric month, a number from 1 to 12. 252.It Ar dd 253Day, a number from 1 to 31. 254.It Ar HH 255Hour, a number from 0 to 23. 256.It Ar MM 257Minutes, a number from 0 to 59. 258.It Ar ss 259Seconds, a number from 0 to 61 260.Pq 59 plus a maximum of two leap seconds . 261.El 262.Pp 263Everything but the minutes is optional. 264.Pp 265Time changes for Daylight Saving Time, standard time, leap seconds, 266and leap years are handled automatically. 267.Sh EXAMPLES 268The command: 269.Bd -literal -offset indent 270date "+DATE: %Y-%m-%d%nTIME: %H:%M:%S" 271.Ed 272.Pp 273will display: 274.Bd -literal -offset indent 275DATE: 1987-11-21 276TIME: 13:36:16 277.Ed 278.Pp 279In the Europe/London timezone, the command: 280.Bd -literal -offset indent 281date -v1m -v+1y 282.Ed 283.Pp 284will display: 285.Bd -literal -offset indent 286Sun Jan 4 04:15:24 GMT 1998 287.Ed 288.Pp 289where it is currently Mon Aug 4 04:15:24 BST 1997. 290.Pp 291The command: 292.Bd -literal -offset indent 293date -v1d -v3m -v0y -v-1d 294.Ed 295.Pp 296will display the last day of February in the year 2000: 297.Bd -literal -offset indent 298Tue Feb 29 03:18:00 GMT 2000 299.Ed 300.Pp 301The command: 302.Bd -literal -offset indent 303date -v1d -v+1m -v-1d -v-fri 304.Ed 305.Pp 306will display the last Friday of the month: 307.Bd -literal -offset indent 308Fri Aug 29 04:31:11 BST 1997 309.Ed 310.Pp 311where it is currently Mon Aug 4 04:31:11 BST 1997. 312.Pp 313The command: 314.Bd -literal -offset indent 315date 8506131627 316.Ed 317.Pp 318sets the date to 319.Dq Li "June 13, 1985, 4:27 PM" . 320.Pp 321The command: 322.Bd -literal -offset indent 323date 1432 324.Ed 325.Pp 326sets the time to 327.Li "2:32 PM" , 328without modifying the date. 329.Sh ENVIRONMENT 330The following environment variables affect the execution of 331.Nm : 332.Bl -tag -width Ds 333.It Ev TZ 334The timezone to use when displaying dates. 335The normal format is a pathname relative to 336.Pa /usr/share/zoneinfo . 337For example, the command 338.Dq TZ=America/Los_Angeles date 339displays the current time in California. 340See 341.Xr environ 7 342for more information. 343.El 344.Sh FILES 345.Bl -tag -width /var/log/messages -compact 346.It Pa /var/log/wtmp 347record of date resets and time changes 348.It Pa /var/log/messages 349record of the user setting the time 350.El 351.Sh SEE ALSO 352.Xr gettimeofday 2 , 353.Xr strftime 3 , 354.Xr strptime 3 , 355.Xr utmp 5 , 356.Xr timed 8 357.Rs 358.%T "TSP: The Time Synchronization Protocol for UNIX 4.3BSD" 359.%A R. Gusella 360.%A S. Zatti 361.Re 362.Sh DIAGNOSTICS 363The 364.Nm 365utility exits 0 on success, 1 if unable to set the date, and 2 366if able to set the local date, but unable to set it globally. 367.Pp 368Occasionally, when 369.Xr timed 8 370synchronizes the time on many hosts, the setting of a new time value may 371require more than a few seconds. 372On these occasions, 373.Nm 374prints: 375.Ql Network time being set . 376The message 377.Ql Communication error with timed 378occurs when the communication 379between 380.Nm 381and 382.Xr timed 8 383fails. 384.Sh STANDARDS 385The 386.Nm 387utility is expected to be compatible with 388.St -p1003.2 . 389.Sh HISTORY 390A 391.Nm 392command appeared in 393.At v1 . 394