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.Dd November 10, 2025 33.Dt DATE 1 34.Os 35.Sh NAME 36.Nm date 37.Nd display or set date and time 38.Sh SYNOPSIS 39.\" Display time. 40.Nm 41.Op Fl nRu 42.Op Fl z Ar output_zone 43.Op Fl I Ns Op Ar FMT 44.Op Fl r Ar filename 45.Op Fl r Ar seconds 46.Oo 47.Sm off 48.Fl v 49.Op Cm + | - 50.Ar val Op Cm y | m | w | d | H | M | S 51.Sm on 52.Oc 53.Op Cm + Ns Ar output_fmt 54.\" Set time with the default input format. 55.Nm 56.Op Fl jnRu 57.Op Fl z Ar output_zone 58.Op Fl I Ns Op Ar FMT 59.Oo 60.Sm off 61.Fl v 62.Op Cm + | - 63.Ar val Op Cm y | m | w | d | H | M | S 64.Sm on 65.Oc 66.Sm off 67.Oo Oo Oo Oo Oo 68.Ar cc Oc 69.Ar yy Oc 70.Ar mm Oc 71.Ar dd Oc 72.Ar HH 73.Oc Ar MM Op Cm \&. Ar SS 74.Sm on 75.Op Cm + Ns Ar output_fmt 76.\" Set time with the user-provided input format. 77.Nm 78.Op Fl jnRu 79.Op Fl z Ar output_zone 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 extended 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 , 144.Cm seconds , 145and 146.Cm ns 147.Pq for nanoseconds . 148The date and time is formatted to the specified precision. 149When 150.Ar FMT 151is 152.Cm hours 153.Po or the more precise 154.Cm minutes , 155.Cm seconds , 156or 157.Cm ns Pc , 158the extended 159.St -iso8601 160format includes the timezone offset. 161.It Fl j 162Do not try to set the date. 163This allows you to use the 164.Fl f 165flag in addition to the 166.Cm + 167option to convert one date format to another. 168Note that any date or time components unspecified by the 169.Fl f 170format string take their values from the current time. 171.It Fl n 172Obsolete flag, accepted and ignored for compatibility. 173.It Fl R 174Use RFC 2822 date and time output format. 175This is equivalent to using 176.Ql %a, %d %b %Y \&%T %z 177as 178.Ar output_fmt 179while 180.Ev LC_TIME 181is set to the 182.Dq C 183locale . 184.It Fl r Ar seconds 185Print the date and time represented by 186.Ar seconds , 187where 188.Ar seconds 189is the number of seconds since the Unix Epoch 190(00:00:00 UTC, January 1, 1970; 191see 192.Xr time 3 ) , 193and can be specified in decimal, octal, or hex. 194.It Fl r Ar filename 195Print the date and time of the last modification of 196.Ar filename . 197.It Fl u 198Display or set the date in UTC (Coordinated Universal) time. 199By default 200.Nm 201displays the time in the time zone described by 202.Pa /etc/localtime 203or the 204.Ev TZ 205environment variable. 206.It Fl z Ar output_zone 207Just before printing the time, change to the specified timezone; 208see the description of 209.Ev TZ 210below. 211This can be used with 212.Fl j 213to easily convert time specifications from one zone to another. 214.It Xo 215.Fl v 216.Sm off 217.Op Cm + | - 218.Ar val Op Cm y | m | w | d | H | M | S 219.Sm on 220.Xc 221Adjust (i.e., take the current date and display the result of the 222adjustment; not actually set the date) the second, minute, hour, month 223day, week day, month or year according to 224.Ar val . 225If 226.Ar val 227is preceded by a plus or minus sign, 228the date is adjusted forward or backward according to the remaining string, 229otherwise the relevant part of the date is set. 230The date can be adjusted as many times as required using these flags. 231Flags are processed in the order given. 232.Pp 233When setting values 234(rather than adjusting them), 235seconds are in the range 0-59, minutes are in the range 0-59, hours are 236in the range 0-23, month days are in the range 1-31, week days are in the 237range 0-6 (Sun-Sat), 238months are in the range 1-12 (Jan-Dec) 239and years are in a limited range depending on the platform. 240.Pp 241On i386, years are in the range 69-38 representing 1969-2038. 242On every other platform, years 0-68 are accepted and represent 2000-2068, and 24369-99 are accepted and represent 1969-1999. 244In both cases, years between 100 and 1900 (both included) are accepted and 245interpreted as relative to 1900 of the Gregorian calendar with a limit of 138 on 246i386 and a much higher limit on every other platform. 247Years starting at 1901 are also accepted, and are interpreted as absolute years. 248.Pp 249If 250.Ar val 251is numeric, one of either 252.Cm y , 253.Cm m , 254.Cm w , 255.Cm d , 256.Cm H , 257.Cm M 258or 259.Cm S 260must be used to specify which part of the date is to be adjusted. 261.Pp 262The week day or month may be specified using a name rather than a 263number. 264If a name is used with the plus 265(or minus) 266sign, the date will be put forwards 267(or backwards) 268to the next 269(previous) 270date that matches the given week day or month. 271This will not adjust the date, 272if the given week day or month is the same as the current one. 273.Pp 274When a date is adjusted to a specific value or in units greater than hours, 275daylight savings time considerations are ignored. 276Adjustments in units of hours or less honor daylight saving time. 277So, assuming the current date is March 26, 0:30 and that the DST adjustment 278means that the clock goes forward at 01:00 to 02:00, using 279.Fl v No +1H 280will adjust the date to March 26, 2:30. 281Likewise, if the date is October 29, 0:30 and the DST adjustment means that 282the clock goes back at 02:00 to 01:00, using 283.Fl v No +3H 284will be necessary to reach October 29, 2:30. 285.Pp 286When the date is adjusted to a specific value that does not actually exist 287(for example March 26, 1:30 BST 2000 in the Europe/London timezone), 288the date will be silently adjusted forward in units of one hour until it 289reaches a valid time. 290When the date is adjusted to a specific value that occurs twice 291(for example October 29, 1:30 2000), 292the resulting timezone will be set so that the date matches the earlier of 293the two times. 294.Pp 295It is not possible to adjust a date to an invalid absolute day, so using 296the switches 297.Fl v No 31d Fl v No 12m 298will simply fail five months of the year. 299It is therefore usual to set the month before setting the day; using 300.Fl v No 12m Fl v No 31d 301always works. 302.Pp 303Adjusting the date by months is inherently ambiguous because 304a month is a unit of variable length depending on the current date. 305This kind of date adjustment is applied in the most intuitive way. 306First of all, 307.Nm 308tries to preserve the day of the month. 309If it is impossible because the target month is shorter than the present one, 310the last day of the target month will be the result. 311For example, using 312.Fl v No +1m 313on May 31 will adjust the date to June 30, while using the same option 314on January 30 will result in the date adjusted to the last day of February. 315This approach is also believed to make the most sense for shell scripting. 316Nevertheless, be aware that going forth and back by the same number of 317months may take you to a different date. 318.Pp 319Refer to the examples below for further details. 320.El 321.Pp 322An operand with a leading plus 323.Pq Sq + 324sign specifies a user-defined format string 325which specifies the format in which to display the date and time. 326The format string may contain any of the conversion specifications 327described in the 328.Xr strftime 3 329manual page, as well as any arbitrary text. 330.Pp 331The following extensions to the regular 332.Xr strftime 3 333syntax are supported: 334.Bl -tag -width "xxxx" 335.It Cm \&% Ns Ar n Ns Cm N 336Replaced by the 337.Ar n Ns 338-digit fractional part of the number of seconds since the Unix Epoch. 339If 340.Ar n 341is omitted or zero, a default value of 9 is used, resulting in a 342number with nanosecond resolution (hence the choice of the letter 343.Sq N 344for this conversion). 345Note that the underlying clock may not necessarily support nanosecond 346resolution. 347.It Cm \&%-N 348As above, but automatically choose the precision based on the reported 349resolution of the underlying clock. 350If the 351.Fl r 352option was specified, the default precision of 9 digits is used. 353.El 354.Pp 355A newline 356.Pq Ql \en 357character is always output after the characters specified by 358the format string. 359The format string for the default display is 360.Dq %+ . 361.Pp 362If an operand does not have a leading plus sign, it is interpreted as 363a value for setting the system's notion of the current date and time. 364The canonical representation for setting the date and time is: 365.Pp 366.Bl -tag -width Ds -compact -offset indent 367.It Ar cc 368Century 369(either 19 or 20) 370prepended to the abbreviated year. 371.It Ar yy 372Year in abbreviated form 373(e.g., 89 for 1989, 06 for 2006). 374.It Ar mm 375Numeric month, a number from 1 to 12. 376.It Ar dd 377Day, a number from 1 to 31. 378.It Ar HH 379Hour, a number from 0 to 23. 380.It Ar MM 381Minutes, a number from 0 to 59. 382.It Ar SS 383Seconds, a number from 0 to 60 384(59 plus a potential leap second). 385.El 386.Pp 387Everything but the minutes is optional. 388.Pp 389.Nm 390understands the time zone definitions from the IANA Time Zone Database, 391.Sy tzdata , 392located in 393.Pa /usr/share/zoneinfo . 394Time changes for Daylight Saving Time, standard time, leap seconds 395and leap years are handled automatically. 396.Pp 397There are two ways to specify the time zone: 398.Pp 399If the file or symlink 400.Pa /etc/localtime 401exists, it is interpreted as a time zone definition file, usually in 402the directory hierarchy 403.Pa /usr/share/zoneinfo , 404which contains the time zone definitions from 405.Sy tzdata . 406.Pp 407If the environment variable 408.Ev TZ 409is set, its value is interpreted as the name of a time zone definition 410file, either an absolute path or a relative path to a time zone 411definition in 412.Pa /usr/share/zoneinfo . 413The 414.Ev TZ 415variable overrides 416.Pa /etc/localtime . 417.Pp 418If the time zone definition file is invalid, 419.Nm 420silently reverts to UTC. 421.Pp 422Previous versions of 423.Nm 424included the 425.Fl d 426(set daylight saving time flag) and 427.Fl t 428(set negative time zone offset) options, but these details are now 429handled automatically by 430.Sy tzdata . 431Modern offsets are positive for time zones ahead of UTC and negative 432for time zones behind UTC, but like the obsolete 433.Fl t 434option, the 435.Sy tzdata 436files in the subdirectory 437.Pa /usr/share/zoneinfo/Etc 438still use an older convention where times ahead of UTC are considered 439negative. 440.Sh ENVIRONMENT 441The following environment variable affects the execution of 442.Nm : 443.Bl -tag -width Ds 444.It Ev TZ 445The timezone to use when displaying dates. 446The normal format is a pathname relative to 447.Pa /usr/share/zoneinfo . 448For example, the command 449.Dq TZ=America/Los_Angeles date 450displays the current time in California. 451The variable can also specify an absolute path. 452See 453.Xr environ 7 454for more information. 455.El 456.Sh FILES 457.Bl -tag -width /var/log/messages -compact 458.It Pa /etc/localtime 459Time zone information file for default system time zone. 460May be omitted, in which case the default time zone is UTC. 461.It Pa /usr/share/zoneinfo 462Directory containing time zone information files. 463.It Pa /var/log/messages 464Record of the user setting the time. 465.It Pa /var/log/utx.log 466Record of date resets and time changes. 467.El 468.Sh EXIT STATUS 469The 470.Nm 471utility exits 0 on success, 1 if unable to set the date, and 2 472if able to set the local date, but unable to set it globally. 473.Sh EXAMPLES 474The command 475.Pp 476.Dl "date +%s.%3N" 477.Pp 478will print the time elapsed since the Unix Epoch with millisecond 479precision. 480.Pp 481The command: 482.Pp 483.Dl "date ""+DATE: %Y-%m-%d%nTIME: %H:%M:%S""" 484.Pp 485will display: 486.Bd -literal -offset indent 487DATE: 1987-11-21 488TIME: 13:36:16 489.Ed 490.Pp 491In the Europe/London timezone, the command: 492.Pp 493.Dl "date -v1m -v+1y" 494.Pp 495will display: 496.Pp 497.Dl "Sun Jan 4 04:15:24 GMT 1998" 498.Pp 499where it is currently 500.Ql "Mon Aug 4 04:15:24 BST 1997" . 501.Pp 502The command: 503.Pp 504.Dl "date -v1d -v3m -v0y -v-1d" 505.Pp 506will display the last day of February in the year 2000: 507.Pp 508.Dl "Tue Feb 29 03:18:00 GMT 2000" 509.Pp 510So will the command: 511.Pp 512.Dl "date -v3m -v30d -v0y -v-1m" 513.Pp 514because there is no such date as the 30th of February. 515.Pp 516The command: 517.Pp 518.Dl "date -v1d -v+1m -v-1d -v-fri" 519.Pp 520will display the last Friday of the month: 521.Pp 522.Dl "Fri Aug 29 04:31:11 BST 1997" 523.Pp 524where it is currently 525.Ql "Mon Aug 4 04:31:11 BST 1997" . 526.Pp 527The command: 528.Pp 529.Dl "date 8506131627" 530.Pp 531sets the date to 532.Ql "June 13, 1985, 4:27 PM" . 533.Pp 534.Dl "date ""+%Y%m%d%H%M.%S""" 535.Pp 536may be used on one machine to print out the date 537suitable for setting on another. 538.Po Use 539.Ql "+%m%d%H%M%Y.%S" 540with GNU date on 541Linux . 542.Pc 543.Pp 544The command: 545.Pp 546.Dl "date 1432" 547.Pp 548sets the time to 549.Ql "2:32 PM" , 550without modifying the date. 551.Pp 552The command 553.Pp 554.Dl "TZ=America/Los_Angeles date -Iseconds -r 1533415339" 555.Pp 556will display 557.Pp 558.Dl "2018-08-04T13:42:19-07:00" 559.Pp 560The command: 561.Pp 562.Dl "env LC_ALL=C date -j -f ""%a %b %d %T %Z %Y"" ""`env LC_ALL=C date`"" ""+%s""" 563.Pp 564can be used to parse the output from 565.Nm 566and express it in Epoch time. 567.Pp 568Finally the command 569.Pp 570.Dl "TZ=America/Los_Angeles date -z Europe/Paris -j 0900" 571.Pp 572will print the time in the 573.Dq Europe/Paris 574timezone when it is 9:00 in the 575.Dq America/Los_Angeles 576timezone. 577.Sh DIAGNOSTICS 578It is invalid to combine the 579.Fl I 580flag with either 581.Fl R 582or an output format 583.Dq ( + Ns ... ) 584operand. 585If this occurs, 586.Nm 587prints: 588.Ql multiple output formats specified 589and exits with status 1. 590.Sh SEE ALSO 591.Xr locale 1 , 592.Xr clock_gettime 2 , 593.Xr gettimeofday 2 , 594.Xr getutxent 3 , 595.Xr strftime 3 , 596.Xr strptime 3 , 597.Xr tzset 3 , 598.Xr adjkerntz 8 , 599.Xr ntpd 8 , 600.Xr tzsetup 8 601.Rs 602.%T "TSP: The Time Synchronization Protocol for UNIX 4.3BSD" 603.%A R. Gusella 604.%A S. Zatti 605.Re 606.Rs 607.%U https://iana.org/time-zones 608.%T Time Zone Database 609.Re 610.Sh STANDARDS 611The 612.Nm 613utility is expected to be compatible with 614.St -p1003.2 . 615With the exception of the 616.Fl u 617option, all options are extensions to the standard. 618.Pp 619The format selected by the 620.Fl I 621flag is compatible with 622.St -iso8601 . 623.Pp 624The 625.Ql \&%N 626conversion specification for nanoseconds is a non-standard extension. 627It is compatible with GNU date's 628.Ql \&%N . 629.Sh HISTORY 630A 631.Nm 632command appeared in 633.At v1 . 634.Pp 635A number of options were added and then removed again, including the 636.Fl d 637(set DST flag) and 638.Fl t 639(set negative time zone offset). 640Time zones are now handled by code bundled with 641.Sy tzdata . 642.Pp 643The 644.Fl I 645flag was added in 646.Fx 12.0 . 647.Pp 648The 649.Ql \&%N 650conversion specification was added in 651.Fx 14.1 . 652Support for the 653.Ql \&% Ns Ar n Ns Cm N 654and 655.Ql \&%-N 656variants was added in 657.Fx 15.1 . 658