1.\"- 2.\" Copyright (c) 1980, 1990, 1993 3.\" The Regents of the University of California. All rights reserved. 4.\" 5.\" This code is derived from software contributed to Berkeley by 6.\" the Institute of Electrical and Electronics Engineers, Inc. 7.\" 8.\" Redistribution and use in source and binary forms, with or without 9.\" modification, are permitted provided that the following conditions 10.\" are met: 11.\" 1. Redistributions of source code must retain the above copyright 12.\" notice, this list of conditions and the following disclaimer. 13.\" 2. Redistributions in binary form must reproduce the above copyright 14.\" notice, this list of conditions and the following disclaimer in the 15.\" documentation and/or other materials provided with the distribution. 16.\" 3. Neither the name of the University nor the names of its contributors 17.\" may be used to endorse or promote products derived from this software 18.\" without specific prior written permission. 19.\" 20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30.\" SUCH DAMAGE. 31.\" 32.\" @(#)date.1 8.3 (Berkeley) 4/28/95 33.\" $FreeBSD$ 34.\" 35.Dd November 3, 2021 36.Dt DATE 1 37.Os 38.Sh NAME 39.Nm date 40.Nd display or set date and time 41.Sh SYNOPSIS 42.\" Display time. 43.Nm 44.Op Fl nRu 45.Op Fl I Ns Op Ar FMT 46.Op Fl r Ar filename 47.Op Fl r Ar seconds 48.Oo 49.Sm off 50.Fl v 51.Op Cm + | - 52.Ar val Op Cm y | m | w | d | H | M | S 53.Sm on 54.Oc 55.Op Cm + Ns Ar output_fmt 56.\" Set time with the default input format. 57.Nm 58.Op Fl jnRu 59.Op Fl I Ns Op Ar FMT 60.Oo 61.Sm off 62.Fl v 63.Op Cm + | - 64.Ar val Op Cm y | m | w | d | H | M | S 65.Sm on 66.Oc 67.Sm off 68.Oo Oo Oo Oo Oo 69.Ar cc Oc 70.Ar yy Oc 71.Ar mm Oc 72.Ar dd Oc 73.Ar HH 74.Oc Ar MM Op Cm \&. Ar SS 75.Sm on 76.Op Cm + Ns Ar output_fmt 77.\" Set time with the user-provided input format. 78.Nm 79.Op Fl jnRu 80.Op Fl I Ns Op Ar FMT 81.Oo 82.Sm off 83.Fl v 84.Op Cm + | - 85.Ar val Op Cm y | m | w | d | H | M | S 86.Sm on 87.Oc 88.Fl f Ar input_fmt 89.Ar new_date 90.Op Cm + Ns Ar output_fmt 91.Sh DESCRIPTION 92When invoked without arguments, the 93.Nm 94utility displays the current date and time. 95Otherwise, depending on the options specified, 96.Nm 97will set the date and time or print it in a user-defined way. 98.Pp 99The 100.Nm 101utility displays the date and time read from the kernel clock. 102When used to set the date and time, 103both the kernel clock and the hardware clock are updated. 104.Pp 105Only the superuser may set the date, 106and if the system securelevel (see 107.Xr securelevel 7 ) 108is greater than 1, 109the time may not be changed by more than 1 second. 110.Pp 111The options are as follows: 112.Bl -tag -width Ds 113.It Fl f Ar input_fmt 114Use 115.Ar input_fmt 116as the format string to parse the 117.Ar new_date 118provided rather than using the default 119.Sm off 120.Oo Oo Oo Oo Oo 121.Ar cc Oc 122.Ar yy Oc 123.Ar mm Oc 124.Ar dd Oc 125.Ar HH 126.Oc Ar MM Op Cm \&. Ar SS 127.Sm on 128format. 129Parsing is done using 130.Xr strptime 3 . 131.It Fl I Ns Op Ar FMT 132Use 133.St -iso8601 134output format. 135.Ar FMT 136may be omitted, in which case the default is 137.Cm date . 138Valid 139.Ar FMT 140values are 141.Cm date , 142.Cm hours , 143.Cm minutes , 144and 145.Cm seconds . 146The date and time is formatted to the specified precision. 147When 148.Ar FMT 149is 150.Cm hours 151(or the more precise 152.Cm minutes 153or 154.Cm seconds ) , 155the 156.St -iso8601 157format includes the timezone. 158.It Fl j 159Do not try to set the date. 160This allows you to use the 161.Fl f 162flag in addition to the 163.Cm + 164option to convert one date format to another. 165Note that any date or time components unspecified by the 166.Fl f 167format string take their values from the current time. 168.It Fl n 169Obsolete flag, accepted and ignored for compatibility. 170.It Fl R 171Use RFC 2822 date and time output format. 172This is equivalent to using 173.Dq Li %a, %d %b %Y \&%T %z 174as 175.Ar output_fmt 176while 177.Ev LC_TIME 178is set to the 179.Dq C 180locale . 181.It Fl r Ar seconds 182Print the date and time represented by 183.Ar seconds , 184where 185.Ar seconds 186is the number of seconds since the Epoch 187(00:00:00 UTC, January 1, 1970; 188see 189.Xr time 3 ) , 190and can be specified in decimal, octal, or hex. 191.It Fl r Ar filename 192Print the date and time of the last modification of 193.Ar filename . 194.It Fl u 195Display or set the date in 196.Tn UTC 197(Coordinated Universal) time. 198.It Xo 199.Fl v 200.Sm off 201.Op Cm + | - 202.Ar val Op Cm y | m | w | d | H | M | S 203.Sm on 204.Xc 205Adjust (i.e., take the current date and display the result of the 206adjustment; not actually set the date) the second, minute, hour, month 207day, week day, month or year according to 208.Ar val . 209If 210.Ar val 211is preceded with a plus or minus sign, 212the date is adjusted forwards or backwards according to the remaining string, 213otherwise the relevant part of the date is set. 214The date can be adjusted as many times as required using these flags. 215Flags are processed in the order given. 216.Pp 217When setting values 218(rather than adjusting them), 219seconds are in the range 0-59, minutes are in the range 0-59, hours are 220in the range 0-23, month days are in the range 1-31, week days are in the 221range 0-6 (Sun-Sat), 222months are in the range 1-12 (Jan-Dec) 223and years are in the range 80-38 or 1980-2038. 224.Pp 225If 226.Ar val 227is numeric, one of either 228.Cm y , 229.Cm m , 230.Cm w , 231.Cm d , 232.Cm H , 233.Cm M 234or 235.Cm S 236must be used to specify which part of the date is to be adjusted. 237.Pp 238The week day or month may be specified using a name rather than a 239number. 240If a name is used with the plus 241(or minus) 242sign, the date will be put forwards 243(or backwards) 244to the next 245(previous) 246date that matches the given week day or month. 247This will not adjust the date, 248if the given week day or month is the same as the current one. 249.Pp 250When a date is adjusted to a specific value or in units greater than hours, 251daylight savings time considerations are ignored. 252Adjustments in units of hours or less honor daylight saving time. 253So, assuming the current date is March 26, 0:30 and that the DST adjustment 254means that the clock goes forward at 01:00 to 02:00, using 255.Fl v No +1H 256will adjust the date to March 26, 2:30. 257Likewise, if the date is October 29, 0:30 and the DST adjustment means that 258the clock goes back at 02:00 to 01:00, using 259.Fl v No +3H 260will be necessary to reach October 29, 2:30. 261.Pp 262When the date is adjusted to a specific value that does not actually exist 263(for example March 26, 1:30 BST 2000 in the Europe/London timezone), 264the date will be silently adjusted forwards in units of one hour until it 265reaches a valid time. 266When the date is adjusted to a specific value that occurs twice 267(for example October 29, 1:30 2000), 268the resulting timezone will be set so that the date matches the earlier of 269the two times. 270.Pp 271It is not possible to adjust a date to an invalid absolute day, so using 272the switches 273.Fl v No 31d Fl v No 12m 274will simply fail five months of the year. 275It is therefore usual to set the month before setting the day; using 276.Fl v No 12m Fl v No 31d 277always works. 278.Pp 279Adjusting the date by months is inherently ambiguous because 280a month is a unit of variable length depending on the current date. 281This kind of date adjustment is applied in the most intuitive way. 282First of all, 283.Nm 284tries to preserve the day of the month. 285If it is impossible because the target month is shorter than the present one, 286the last day of the target month will be the result. 287For example, using 288.Fl v No +1m 289on May 31 will adjust the date to June 30, while using the same option 290on January 30 will result in the date adjusted to the last day of February. 291This approach is also believed to make the most sense for shell scripting. 292Nevertheless, be aware that going forth and back by the same number of 293months may take you to a different date. 294.Pp 295Refer to the examples below for further details. 296.El 297.Pp 298An operand with a leading plus 299.Pq Sq + 300sign signals a user-defined format string 301which specifies the format in which to display the date and time. 302The format string may contain any of the conversion specifications 303described in the 304.Xr strftime 3 305manual page, as well as any arbitrary text. 306A newline 307.Pq Ql \en 308character is always output after the characters specified by 309the format string. 310The format string for the default display is 311.Dq +%+ . 312.Pp 313If an operand does not have a leading plus sign, it is interpreted as 314a value for setting the system's notion of the current date and time. 315The canonical representation for setting the date and time is: 316.Pp 317.Bl -tag -width Ds -compact -offset indent 318.It Ar cc 319Century 320(either 19 or 20) 321prepended to the abbreviated year. 322.It Ar yy 323Year in abbreviated form 324(e.g., 89 for 1989, 06 for 2006). 325.It Ar mm 326Numeric month, a number from 1 to 12. 327.It Ar dd 328Day, a number from 1 to 31. 329.It Ar HH 330Hour, a number from 0 to 23. 331.It Ar MM 332Minutes, a number from 0 to 59. 333.It Ar SS 334Seconds, a number from 0 to 60 335(59 plus a potential leap second). 336.El 337.Pp 338Everything but the minutes is optional. 339.Pp 340Time changes for Daylight Saving Time, standard time, leap seconds, 341and leap years are handled automatically. 342.Sh ENVIRONMENT 343The following environment variables affect the execution of 344.Nm : 345.Bl -tag -width Ds 346.It Ev TZ 347The timezone to use when displaying dates. 348The normal format is a pathname relative to 349.Pa /usr/share/zoneinfo . 350For example, the command 351.Dq TZ=America/Los_Angeles date 352displays the current time in California. 353See 354.Xr environ 7 355for more information. 356.El 357.Sh FILES 358.Bl -tag -width /var/log/messages -compact 359.It Pa /var/log/utx.log 360record of date resets and time changes 361.It Pa /var/log/messages 362record of the user setting the time 363.El 364.Sh EXIT STATUS 365The 366.Nm 367utility exits 0 on success, 1 if unable to set the date, and 2 368if able to set the local date, but unable to set it globally. 369.Sh EXAMPLES 370The command: 371.Pp 372.Dl "date ""+DATE: %Y-%m-%d%nTIME: %H:%M:%S""" 373.Pp 374will display: 375.Bd -literal -offset indent 376DATE: 1987-11-21 377TIME: 13:36:16 378.Ed 379.Pp 380In the Europe/London timezone, the command: 381.Pp 382.Dl "date -v1m -v+1y" 383.Pp 384will display: 385.Pp 386.Dl "Sun Jan 4 04:15:24 GMT 1998" 387.Pp 388where it is currently 389.Li "Mon Aug 4 04:15:24 BST 1997" . 390.Pp 391The command: 392.Pp 393.Dl "date -v1d -v3m -v0y -v-1d" 394.Pp 395will display the last day of February in the year 2000: 396.Pp 397.Dl "Tue Feb 29 03:18:00 GMT 2000" 398.Pp 399So will the command: 400.Pp 401.Dl "date -v3m -v30d -v0y -v-1m" 402.Pp 403because there is no such date as the 30th of February. 404.Pp 405The command: 406.Pp 407.Dl "date -v1d -v+1m -v-1d -v-fri" 408.Pp 409will display the last Friday of the month: 410.Pp 411.Dl "Fri Aug 29 04:31:11 BST 1997" 412.Pp 413where it is currently 414.Li "Mon Aug 4 04:31:11 BST 1997" . 415.Pp 416The command: 417.Pp 418.Dl "date 8506131627" 419.Pp 420sets the date to 421.Dq Li "June 13, 1985, 4:27 PM" . 422.Pp 423.Dl "date ""+%Y%m%d%H%M.%S""" 424.Pp 425may be used on one machine to print out the date 426suitable for setting on another. 427.Qq ( Li "+%m%d%H%M%Y.%S" 428for use on 429.Tn Linux . ) 430.Pp 431The command: 432.Pp 433.Dl "date 1432" 434.Pp 435sets the time to 436.Li "2:32 PM" , 437without modifying the date. 438.Pp 439The command 440.Pp 441.Dl "TZ=America/Los_Angeles date -Iseconds -r 1533415339" 442.Pp 443will display 444.Pp 445.Dl "2018-08-04T13:42:19-07:00" 446.Pp 447Finally the command: 448.Pp 449.Dl "date -j -f ""%a %b %d %T %Z %Y"" ""`LC_ALL=C date`"" ""+%s""" 450.Pp 451can be used to parse the output from 452.Nm 453and express it in Epoch time. 454.Sh DIAGNOSTICS 455It is invalid to combine the 456.Fl I 457flag with either 458.Fl R 459or an output format 460.Dq ( + Ns ... ) 461operand. 462If this occurs, 463.Nm 464prints: 465.Ql multiple output formats specified 466and exits with an error status. 467.Sh SEE ALSO 468.Xr locale 1 , 469.Xr gettimeofday 2 , 470.Xr getutxent 3 , 471.Xr strftime 3 , 472.Xr strptime 3 473.Rs 474.%T "TSP: The Time Synchronization Protocol for UNIX 4.3BSD" 475.%A R. Gusella 476.%A S. Zatti 477.Re 478.Sh STANDARDS 479The 480.Nm 481utility is expected to be compatible with 482.St -p1003.2 . 483The 484.Fl f , I , j , r , 485and 486.Fl v 487options are all extensions to the standard. 488.Pp 489The format selected by the 490.Fl I 491flag is compatible with 492.St -iso8601 . 493.Sh HISTORY 494A 495.Nm 496command appeared in 497.At v1 . 498.Pp 499The 500.Fl I 501flag was added in 502.Fx 12.0 . 503