getdate.texi
来自「gnu tar 源码包。 tar 软件是 Unix 系统下的一个打包软件」· TEXI 代码 · 共 554 行 · 第 1/2 页
TEXI
554 行
@c GNU date syntax documentation@c Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,@c 2003, 2004, 2005, 2006 Free Software Foundation, Inc.@c Permission is granted to copy, distribute and/or modify this document@c under the terms of the GNU Free Documentation License, Version 1.2 or@c any later version published by the Free Software Foundation; with no@c Invariant Sections, with no Front-Cover Texts, and with no Back-Cover@c Texts. A copy of the license is included in the ``GNU Free@c Documentation License'' file as part of this distribution.@node Date input formats@chapter Date input formats@cindex date input formats@findex get_dateFirst, a quote:@quotationOur units of temporal measurement, from seconds on up to months, are socomplicated, asymmetrical and disjunctive so as to make coherent mentalreckoning in time all but impossible. Indeed, had some tyrannical godcontrived to enslave our minds to time, to make it all but impossiblefor us to escape subjection to sodden routines and unpleasant surprises,he could hardly have done better than handing down our present system.It is like a set of trapezoidal building blocks, with no vertical orhorizontal surfaces, like a language in which the simplest thoughtdemands ornate constructions, useless particles and lengthycircumlocutions. Unlike the more successful patterns of language andscience, which enable us to face experience boldly or at leastlevel-headedly, our system of temporal calculation silently andpersistently encourages our terror of time.@dots{} It is as though architects had to measure length in feet, widthin meters and height in ells; as though basic instruction manualsdemanded a knowledge of five different languages. It is no wonder thenthat we often look into our own immediate past or future, last Tuesdayor a week from Sunday, with feelings of helpless confusion. @dots{}--- Robert Grudin, @cite{Time and the Art of Living}.@end quotationThis section describes the textual date representations that @sc{gnu}programs accept. These are the strings you, as a user, can supply asarguments to the various programs. The C interface (via the@code{get_date} function) is not described here.@menu* General date syntax:: Common rules.* Calendar date items:: 19 Dec 1994.* Time of day items:: 9:20pm.* Time zone items:: @sc{est}, @sc{pdt}, @sc{gmt}.* Day of week items:: Monday and others.* Relative items in date strings:: next tuesday, 2 years ago.* Pure numbers in date strings:: 19931219, 1440.* Seconds since the Epoch:: @@1078100502.* Specifying time zone rules:: TZ="America/New_York", TZ="UTC0".* Authors of get_date:: Bellovin, Eggert, Salz, Berets, et al.@end menu@node General date syntax@section General date syntax@cindex general date syntax@cindex items in date stringsA @dfn{date} is a string, possibly empty, containing many itemsseparated by whitespace. The whitespace may be omitted when noambiguity arises. The empty string means the beginning of today (i.e.,midnight). Order of the items is immaterial. A date string may containmany flavors of items:@itemize @bullet@item calendar date items@item time of day items@item time zone items@item day of the week items@item relative items@item pure numbers.@end itemize@noindent We describe each of these item types in turn, below.@cindex numbers, written-out@cindex ordinal numbers@findex first @r{in date strings}@findex next @r{in date strings}@findex last @r{in date strings}A few ordinal numbers may be written out in words in some contexts. This ismost useful for specifying day of the week items or relative items (seebelow). Among the most commonly used ordinal numbers, the word@samp{last} stands for @math{-1}, @samp{this} stands for 0, and@samp{first} and @samp{next} both stand for 1. Because the word@samp{second} stands for the unit of time there is no way to write theordinal number 2, but for convenience @samp{third} stands for 3,@samp{fourth} for 4, @samp{fifth} for 5,@samp{sixth} for 6, @samp{seventh} for 7, @samp{eighth} for 8,@samp{ninth} for 9, @samp{tenth} for 10, @samp{eleventh} for 11 and@samp{twelfth} for 12.@cindex months, written-outWhen a month is written this way, it is still considered to be writtennumerically, instead of being ``spelled in full''; this changes theallowed strings.@cindex language, in datesIn the current implementation, only English is supported for words andabbreviations like @samp{AM}, @samp{DST}, @samp{EST}, @samp{first},@samp{January}, @samp{Sunday}, @samp{tomorrow}, and @samp{year}.@cindex language, in dates@cindex time zone itemThe output of the @command{date} commandis not always acceptable as a date string,not only because of the language problem, but also because there is nostandard meaning for time zone items like @samp{IST}. When using@command{date} to generate a date string intended to be parsed later,specify a date format that is independent of language and that does notuse time zone items other than @samp{UTC} and @samp{Z}. Here are someways to do this:@example$ LC_ALL=C TZ=UTC0 dateMon Mar 1 00:21:42 UTC 2004$ TZ=UTC0 date +'%Y-%m-%d %H:%M:%SZ'2004-03-01 00:21:42Z$ date --iso-8601=ns | tr T ' ' # --iso-8601 is a GNU extension.2004-02-29 16:21:42,692722128-0800$ date --rfc-2822 # a GNU extensionSun, 29 Feb 2004 16:21:42 -0800$ date +'%Y-%m-%d %H:%M:%S %z' # %z is a GNU extension.2004-02-29 16:21:42 -0800$ date +'@@%s.%N' # %s and %N are GNU extensions.@@1078100502.692722128@end example@cindex case, ignored in dates@cindex comments, in datesAlphabetic case is completely ignored in dates. Comments may be introducedbetween round parentheses, as long as included parentheses are properlynested. Hyphens not followed by a digit are currently ignored. Leadingzeros on numbers are ignored.Invalid dates like @samp{2005-02-29} or times like @samp{24:00} arerejected. In the typical case of a host that does not support leapseconds, a time like @samp{23:59:60} is rejected even if itcorresponds to a valid leap second.@node Calendar date items@section Calendar date items@cindex calendar date itemA @dfn{calendar date item} specifies a day of the year. It isspecified differently, depending on whether the month is specifiednumerically or literally. All these strings specify the same calendar date:@example1972-09-24 # @sc{iso} 8601.72-9-24 # Assume 19xx for 69 through 99, # 20xx for 00 through 68.72-09-24 # Leading zeros are ignored.9/24/72 # Common U.S. writing.24 September 197224 Sept 72 # September has a special abbreviation.24 Sep 72 # Three-letter abbreviations always allowed.Sep 24, 197224-sep-7224sep72@end exampleThe year can also be omitted. In this case, the last specified year isused, or the current year if none. For example:@example9/24sep 24@end exampleHere are the rules.@cindex @sc{iso} 8601 date format@cindex date format, @sc{iso} 8601For numeric months, the @sc{iso} 8601 format@samp{@var{year}-@var{month}-@var{day}} is allowed, where @var{year} isany positive number, @var{month} is a number between 01 and 12, and@var{day} is a number between 01 and 31. A leading zero must be presentif a number is less than ten. If @var{year} is 68 or smaller, then 2000is added to it; otherwise, if @var{year} is less than 100,then 1900 is added to it. The construct@samp{@var{month}/@var{day}/@var{year}}, popular in the United States,is accepted. Also @samp{@var{month}/@var{day}}, omitting the year.@cindex month names in date strings@cindex abbreviations for monthsLiteral months may be spelled out in full: @samp{January},@samp{February}, @samp{March}, @samp{April}, @samp{May}, @samp{June},@samp{July}, @samp{August}, @samp{September}, @samp{October},@samp{November} or @samp{December}. Literal months may be abbreviatedto their first three letters, possibly followed by an abbreviating dot.It is also permitted to write @samp{Sept} instead of @samp{September}.When months are written literally, the calendar date may be given as anyof the following:@example@var{day} @var{month} @var{year}@var{day} @var{month}@var{month} @var{day} @var{year}@var{day}-@var{month}-@var{year}@end exampleOr, omitting the year:@example@var{month} @var{day}@end example@node Time of day items@section Time of day items@cindex time of day itemA @dfn{time of day item} in date strings specifies the time on a givenday. Here are some examples, all of which represent the same time:@example20:02:00.00000020:028:02pm20:02-0500 # In @sc{est} (U.S. Eastern Standard Time).@end exampleMore generally, the time of day may be given as@samp{@var{hour}:@var{minute}:@var{second}}, where @var{hour} isa number between 0 and 23, @var{minute} is a number between 0 and59, and @var{second} is a number between 0 and 59 possibly followed by@samp{.} or @samp{,} and a fraction containing one or more digits.Alternatively,@samp{:@var{second}} can be omitted, in which case it is taken tobe zero. On the rare hosts that support leap seconds, @var{second}may be 60.@findex am @r{in date strings}@findex pm @r{in date strings}@findex midnight @r{in date strings}@findex noon @r{in date strings}If the time is followed by @samp{am} or @samp{pm} (or @samp{a.m.}or @samp{p.m.}), @var{hour} is restricted to run from 1 to 12, and@samp{:@var{minute}} may be omitted (taken to be zero). @samp{am}indicates the first half of the day, @samp{pm} indicates the secondhalf of the day. In this notation, 12 is the predecessor of 1:midnight is @samp{12am} while noon is @samp{12pm}.(This is the zero-oriented interpretation of @samp{12am} and @samp{12pm},as opposed to the old tradition derived from Latinwhich uses @samp{12m} for noon and @samp{12pm} for midnight.)@cindex time zone correction@cindex minutes, time zone correction byThe time may alternatively be followed by a time zone correction,expressed as @samp{@var{s}@var{hh}@var{mm}}, where @var{s} is @samp{+}or @samp{-}, @var{hh} is a number of zone hours and @var{mm} is a numberof zone minutes. You can also separate @var{hh} from @var{mm} with a colon.When a time zone correction is given this way, itforces interpretation of the time relative toCoordinated Universal Time (@sc{utc}), overriding any previousspecification for the time zone or the local time zone. For example,@samp{+0530} and @samp{+05:30} both stand for the time zone 5.5 hoursahead of @sc{utc} (e.g., India). The @var{minute}part of the time of day may not be elided when a time zone correctionis used. This is the best way to specify a time zone correction byfractional parts of an hour.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?