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