1*5a5d821fSkre.\" $NetBSD: date.1,v 1.57 2024/09/17 15:25:39 kre Exp $ 249f0ad86Scgd.\" 3667b5ea1Smycroft.\" Copyright (c) 1980, 1990, 1993 4667b5ea1Smycroft.\" The Regents of the University of California. All rights reserved. 561f28255Scgd.\" 661f28255Scgd.\" This code is derived from software contributed to Berkeley by 761f28255Scgd.\" the Institute of Electrical and Electronics Engineers, Inc. 861f28255Scgd.\" 961f28255Scgd.\" Redistribution and use in source and binary forms, with or without 1061f28255Scgd.\" modification, are permitted provided that the following conditions 1161f28255Scgd.\" are met: 1261f28255Scgd.\" 1. Redistributions of source code must retain the above copyright 1361f28255Scgd.\" notice, this list of conditions and the following disclaimer. 1461f28255Scgd.\" 2. Redistributions in binary form must reproduce the above copyright 1561f28255Scgd.\" notice, this list of conditions and the following disclaimer in the 1661f28255Scgd.\" documentation and/or other materials provided with the distribution. 17b5b29542Sagc.\" 3. Neither the name of the University nor the names of its contributors 1861f28255Scgd.\" may be used to endorse or promote products derived from this software 1961f28255Scgd.\" without specific prior written permission. 2061f28255Scgd.\" 2161f28255Scgd.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2261f28255Scgd.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2361f28255Scgd.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2461f28255Scgd.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2561f28255Scgd.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2661f28255Scgd.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2761f28255Scgd.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2861f28255Scgd.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2961f28255Scgd.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3061f28255Scgd.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3161f28255Scgd.\" SUCH DAMAGE. 3261f28255Scgd.\" 335fc5415eSjtc.\" @(#)date.1 8.3 (Berkeley) 4/28/95 34346aa5ddScgd.\" 358dd8bcf3Skre.Dd September 17, 2024 3661f28255Scgd.Dt DATE 1 3761f28255Scgd.Os 3861f28255Scgd.Sh NAME 3961f28255Scgd.Nm date 40667b5ea1Smycroft.Nd display or set date and time 4161f28255Scgd.Sh SYNOPSIS 42c3872193Senami.Nm 4302f83b58Skre.Op Fl ajnRUu 44aa62ece7Schristos.Op Fl d Ar date 45c7273dc9Smycroft.Op Fl r Ar seconds 4602f83b58Skre.Op Fl z Ar zone 4761f28255Scgd.Op Cm + Ns Ar format 48080f6953Sbjh21.Sm off 49a2db434eSuwe.Oo 50a2db434eSuwe.Oo Oo Oo Oo Oo 515d27a9d6Sjdarrow.Ar CC Oc 52080f6953Sbjh21.Ar yy Oc 53080f6953Sbjh21.Ar mm Oc 54080f6953Sbjh21.Ar dd Oc 55a2db434eSuwe.Ar HH Oc 56a2db434eSuwe.Ar MM 57a2db434eSuwe.Op Cm \&. Ar SS 58a2db434eSuwe.Oc 59080f6953Sbjh21.Sm on 609337b5ddSchristos.Nm 6104f2a3c1Skim.Op Fl ajnRu 629337b5ddSchristos.Fl f Ar input_format 638710cd3bSuwe.Ar new_date 649337b5ddSchristos.Op Cm + Ns Ar format 6561f28255Scgd.Sh DESCRIPTION 66c3872193Senami.Nm 6761f28255Scgddisplays the current date and time when invoked without arguments. 6861f28255ScgdProviding arguments will format the date and time in a user-defined 6961f28255Scgdway or set the date. 7061f28255ScgdOnly the superuser may set the date. 7161f28255Scgd.Pp 7261f28255ScgdThe options are as follows: 738710cd3bSuwe.Bl -tag -width Fl 74a7151c0aSdsl.It Fl a 75a7151c0aSdslUse 76a7151c0aSdsl.Xr adjtime 2 77a7151c0aSdslto change the local system time slowly, 78a7151c0aSdslmaintaining it as a monotonically increasing function. 79a7151c0aSdsl.Fl a 80a7151c0aSdslimplies 81a7151c0aSdsl.Fl n . 82aa62ece7Schristos.It Fl d Ar date 83aa62ece7SchristosParse the provided human-described date and time and display the result without 845d27a9d6Sjdarrowactually changing the system clock. 85c0410f48Sreed(See 86c0410f48Sreed.Xr parsedate 3 87c0410f48Sreedfor examples.) 889337b5ddSchristos.It Fl f Ar input_fmt 899337b5ddSchristosUse 909337b5ddSchristos.Ar input_fmt 919337b5ddSchristosas the format string to parse the 929337b5ddSchristos.Ar new_date 939337b5ddSchristosprovided rather than using the default 949337b5ddSchristos.Sm off 959337b5ddSchristos.Oo Oo Oo Oo Oo 968710cd3bSuwe.Ar CC Oc 979337b5ddSchristos.Ar yy Oc 989337b5ddSchristos.Ar mm Oc 999337b5ddSchristos.Ar dd Oc 100a2db434eSuwe.Ar HH Oc 101a2db434eSuwe.Ar MM 102a2db434eSuwe.Op Cm \&. Ar SS 1039337b5ddSchristos.Sm on 1049337b5ddSchristosformat. 1059337b5ddSchristosParsing is done using 1069337b5ddSchristos.Xr strptime 3 . 107aa62ece7Schristos.It Fl j 108aa62ece7SchristosParse the provided canonical representation of date and time (described below) 109aa62ece7Schristosand display the result without actually changing the system clock. 11061f28255Scgd.It Fl n 11161f28255ScgdThe utility 11261f28255Scgd.Xr timed 8 113667b5ea1Smycroftis used to synchronize the clocks on groups of machines. 11461f28255ScgdBy default, if 115c2727224Swiz.Xr timed 8 11661f28255Scgdis running, 117c3872193Senami.Nm 11861f28255Scgdwill set the time on all of the machines in the local group. 11961f28255ScgdThe 12061f28255Scgd.Fl n 12161f28255Scgdoption stops 122c3872193Senami.Nm 12361f28255Scgdfrom setting the time for other than the current machine. 12404f2a3c1Skim.It Fl R 12504f2a3c1SkimUse a default display format that conforms to the date and time 12604f2a3c1Skimspecification in RFC 5322 (Internet Message Format). 12781a4d4f0Sreed.It Fl r Ar seconds 1280166097dSmycroftPrint out the date and time that is 12961f28255Scgd.Ar seconds 13061f28255Scgdfrom the Epoch. 13102f83b58Skre.It Fl U 13202f83b58SkreReset the timezone used by 13302f83b58Skre.Nm 13402f83b58Skreto that which existed when it was invoked. 13502f83b58SkreThis is only useful after an earlier 13602f83b58Skre.Fl u 13702f83b58Skreor 13802f83b58Skre.Fl z 13902f83b58Skreoption. 14061f28255Scgd.It Fl u 141e793fb46SwizDisplay or set the date in UTC (universal) time. 14202f83b58Skre.It Fl z Ar zone 14302f83b58SkreSet the timezone to be used by 14402f83b58Skre.Nm 14502f83b58Skreto 14602f83b58Skre.Ar zone . 14702f83b58SkreIf 14802f83b58Skre.Ar zone 14902f83b58Skreis an empty string, revert to the system's 15002f83b58Skredefault timezone (ignoring any setting of 15102f83b58Skre.Ev TZ ) . 15261f28255Scgd.El 15361f28255Scgd.Pp 1548dd8bcf3SkreNote the 15502f83b58Skre.Fl d , 15602f83b58Skre.Fl U , 15702f83b58Skre.Fl u , 1588dd8bcf3Skreand 15902f83b58Skre.Fl z 1608dd8bcf3Skreoptions are applied when encountered, hence specifying 1618dd8bcf3Skre.Fl u 1628dd8bcf3Skrebefore 1638dd8bcf3Skre.Fl d 1648dd8bcf3Skrewill cause the 1658dd8bcf3Skre.Ar date 1668dd8bcf3Skreto be parsed as coordinated universal time, by default, 1678dd8bcf3Skrewhereas if 1688dd8bcf3Skre.Fl u 1698dd8bcf3Skreis specified after 1708dd8bcf3Skre.Fl d 1718dd8bcf3Skrethe 1728dd8bcf3Skre.Ar date 1738dd8bcf3Skrewill be parsed using the default timezone, then 1748dd8bcf3Skreoutput will be generated in UTC. 1758dd8bcf3Skre.Pp 176080f6953Sbjh21An operand with a leading plus 177080f6953Sbjh21.Pq Cm + 178080f6953Sbjh21sign signals a user-defined format 17961f28255Scgdstring which specifies the format in which to display the date and time. 18061f28255ScgdThe format string may contain any of the conversion specifications described 18161f28255Scgdin the 18261f28255Scgd.Xr strftime 3 18361f28255Scgdmanual page, as well as any arbitrary text. 1848710cd3bSuweA 1858710cd3bSuwe.Aq newline 1868710cd3bSuwecharacter is always output after the characters 18714dfaa4bSwizspecified by the format string. 18861f28255ScgdThe format string for the default display is: 1890a751ce1Suwe.Pp 1900a751ce1Suwe.Dl %a %b %e %H:%M:%S %Z %Y 19161f28255Scgd.Pp 19261f28255ScgdIf an operand does not have a leading plus sign, it is interpreted as 19361f28255Scgda value for setting the system's notion of the current date and time. 194667b5ea1SmycroftThe canonical representation for setting the date and time is: 19561f28255Scgd.Pp 19661f28255Scgd.Bl -tag -width Ds -compact -offset indent 1975d27a9d6Sjdarrow.It Ar CC 198f9a6471eSmycroftThe first two digits of the year (the century). 19961f28255Scgd.It Ar yy 20014dfaa4bSwizThe second two digits of the year. 20114dfaa4bSwizIf 202080f6953Sbjh21.Ar yy 203f9a6471eSmycroftis specified, but 2045d27a9d6Sjdarrow.Ar CC 205f9a6471eSmycroftis not, a value for 206080f6953Sbjh21.Ar yy 207f9a6471eSmycroftbetween 69 and 99 results in a 2085d27a9d6Sjdarrow.Ar CC 20914dfaa4bSwizvalue of 19. 21014dfaa4bSwizOtherwise, a 2115d27a9d6Sjdarrow.Ar CC 212f9a6471eSmycroftvalue of 20 is used. 21361f28255Scgd.It Ar mm 214080f6953Sbjh21The month of the year, from 01 to 12. 21561f28255Scgd.It Ar dd 216080f6953Sbjh21The day of the month, from 01 to 31. 2175d27a9d6Sjdarrow.It Ar HH 218080f6953Sbjh21The hour of the day, from 00 to 23. 2195d27a9d6Sjdarrow.It Ar MM 220080f6953Sbjh21The minute of the hour, from 00 to 59. 2215d27a9d6Sjdarrow.It Ar SS 2221bd07c5dSabhinavThe second of the minute, from 00 to 60. 22361f28255Scgd.El 22461f28255Scgd.Pp 225667b5ea1SmycroftEverything but the minutes is optional. 22661f28255Scgd.Pp 227c2727224SwizTime changes for Daylight Saving and Standard Time and leap seconds 22861f28255Scgdand years are handled automatically. 22922f1ac50Swiz.Sh ENVIRONMENT 23022f1ac50SwizThe following environment variables affect the execution of 231990562bfSwiz.Nm : 2328710cd3bSuwe.Bl -tag -width Ev 23322f1ac50Swiz.It Ev TZ 23422f1ac50SwizThe timezone to use when displaying dates. 23522f1ac50SwizSee 23622f1ac50Swiz.Xr environ 7 23722f1ac50Swizfor more information. 23822f1ac50Swiz.El 23922f1ac50Swiz.Sh FILES 2408710cd3bSuwe.Bl -tag -width Pa -compact 24122f1ac50Swiz.It Pa /etc/localtime 24222f1ac50SwizSymlink pointing to system's default timezone information file in 24322f1ac50Swiz.Pa /usr/share/zoneinfo 24422f1ac50Swizdirectory. 2458710cd3bSuwe.It Pa /usr/lib/locale/ Ns Ao Ar L Ac Ns Pa /LC_TIME 2468710cd3bSuweDescription of time locale 2478710cd3bSuwe.Aq Ar L . 248a61f9804Schristos.It Pa /usr/share/zoneinfo 249a61f9804SchristosTime zone information directory. 250a61f9804Schristos.It Pa /usr/share/zoneinfo/posixrules 251a61f9804SchristosUsed with POSIX-style TZ's. 252a61f9804Schristos.It Pa /usr/share/zoneinfo/GMT 253a61f9804SchristosFor UTC leap seconds. 25422f1ac50Swiz.It Pa /var/log/wtmp 25522f1ac50SwizA record of date resets and time changes. 25622f1ac50Swiz.It Pa /var/log/messages 25722f1ac50SwizA record of the user setting the time. 25822f1ac50Swiz.El 259a61f9804Schristos.Pp 260a61f9804SchristosIf 261a61f9804Schristos.Pa /usr/share/zoneinfo/GMT 262a61f9804Schristosis absent, UTC leap seconds are loaded from 263a61f9804Schristos.Pa /usr/share/zoneinfo/posixrules . 26461f28255Scgd.Sh EXAMPLES 26561f28255ScgdThe command: 2660a751ce1Suwe.Pp 2670a751ce1Suwe.Dl date '+DATE: %m/%d/%y%nTIME: %H:%M:%S' 26861f28255Scgd.Pp 26961f28255Scgdwill display: 27061f28255Scgd.Bd -literal -offset indent 27161f28255ScgdDATE: 11/21/87 27261f28255ScgdTIME: 13:36:16 27361f28255Scgd.Ed 27461f28255Scgd.Pp 27561f28255ScgdThe command: 2760a751ce1Suwe.Pp 2770a751ce1Suwe.Dl date 8506131627 27861f28255Scgd.Pp 27961f28255Scgdsets the date to 280667b5ea1Smycroft.Dq Li "June 13, 1985, 4:27 PM" . 28161f28255Scgd.Pp 28261f28255ScgdThe command: 2830a751ce1Suwe.Pp 2840a751ce1Suwe.Dl date 1432 28561f28255Scgd.Pp 28661f28255Scgdsets the time to 28761f28255Scgd.Li "2:32 PM" , 28861f28255Scgdwithout modifying the date. 28981476349Swiz.Pp 29081476349SwizThe command: 2910a751ce1Suwe.Pp 2920a751ce1Suwe.Dl date +%s 29381476349Swiz.Pp 29481476349Swizprints the current time as seconds since the Epoch. 29502f83b58Skre.Pp 29602f83b58SkreThe command: 29702f83b58Skre.Pp 29802f83b58Skre.Dl date -z America/Chicago -d 13:00 -z Asia/Tokyo +%H:%M 29902f83b58Skre.Pp 30002f83b58Skreindicates what the time will be in Tokyo when it is 13:00 30102f83b58Skrein Chicago. 30202f83b58SkreAny 30302f83b58Skre.Xr strftime 3 30402f83b58Skrestring could be used for the output. 30502f83b58SkreThe first 30602f83b58Skre.Fl z 30702f83b58Skreoption can be omitted to parse the time as specified by 30802f83b58Skre.Ev TZ 30902f83b58Skre.Pq usually the local timezone , 31002f83b58Skreor the second could be replaced by 31102f83b58Skre.Fl U 31202f83b58Skreto show the parsed time in the local timezone. 313*5a5d821fSkre.Pp 314*5a5d821fSkreEither of the commands: 315*5a5d821fSkre.Pp 316*5a5d821fSkre.Dl date -u -d 1970-01-01T00:00:00 -U +%c 317*5a5d821fSkre.Dl date -r 0 +%c 318*5a5d821fSkre.Pp 319*5a5d821fSkreprint the local time of the 320*5a5d821fSkre.Ux 321*5a5d821fSkreepoch. 32261f28255Scgd.Sh DIAGNOSTICS 32361f28255ScgdExit status is 0 on success, 1 if unable to set the date, and 2 324667b5ea1Smycroftif able to set the local date, but unable to set it globally. 32561f28255Scgd.Pp 32661f28255ScgdOccasionally, when 327bd361a3aSmikel.Xr timed 8 32861f28255Scgdsynchronizes the time on many hosts, the setting of a new time value may 32961f28255Scgdrequire more than a few seconds. 33061f28255ScgdOn these occasions, 331c3872193Senami.Nm 33261f28255Scgdprints: 33361f28255Scgd.Ql Network time being set . 33461f28255ScgdThe message 335c2727224Swiz.Ql Communication error with 336c2727224Swiz.Xr timed 8 33761f28255Scgdoccurs when the communication 33861f28255Scgdbetween 339c3872193Senami.Nm 34061f28255Scgdand 341c2727224Swiz.Xr timed 8 34261f28255Scgdfails. 34322f1ac50Swiz.Sh SEE ALSO 344a7151c0aSdsl.Xr adjtime 2 , 34522f1ac50Swiz.Xr gettimeofday 2 , 34622f1ac50Swiz.Xr settimeofday 2 , 347ab56b9a7Schristos.Xr parsedate 3 , 34822f1ac50Swiz.Xr strftime 3 , 34922f1ac50Swiz.Xr utmp 5 , 350c2727224Swiz.Xr environ 7 , 35122f1ac50Swiz.Xr timed 8 35222f1ac50Swiz.Rs 35322f1ac50Swiz.%T "TSP: The Time Synchronization Protocol for UNIX 4.3BSD" 35422f1ac50Swiz.%A R. Gusella 35522f1ac50Swiz.%A S. Zatti 35622f1ac50Swiz.Re 357a5960e19Sjtc.Sh STANDARDS 35861f28255ScgdThe 359c3872193Senami.Nm 36023e6aab1Sjtcutility is expected to be compatible with 361667b5ea1Smycroft.St -p1003.2 . 362*5a5d821fSkreHowever, achieving true compatability requires running 363*5a5d821fSkre.Nm 364*5a5d821fSkrewith the environment variable 365*5a5d821fSkre.Ev POSIXLY_CORRECT 366*5a5d821fSkreset, in order to parse the time string in the 367*5a5d821fSkrearchaic format POSIX demands, rather than the 368*5a5d821fSkremore rational version described above. 36972d159d5Ssevan.Sh HISTORY 37072d159d5SsevanA 37172d159d5Ssevan.Nm 37272d159d5Ssevanutility appeared in 37372d159d5Ssevan.At v1 . 374