📄 getdate.texi
字号:
@node Date input formats@chapter Date input formats@cindex date input formats@findex getdateFirst, 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{getdate} function) is not described here.@cindex beginning of time, for @acronym{POSIX}@cindex epoch, for @acronym{POSIX}Although the date syntax here can represent any possible time since theyear zero, computer integers often cannot represent such a wide range oftime. On @acronym{POSIX} systems, the clock starts at 1970-01-01 00:00:00@sc{utc}: @acronym{POSIX} does not require support for times before the@acronym{POSIX} Epoch and times far in the future. Traditional Unix systemshave 32-bit signed @code{time_t} and can represent times from 1901-12-1320:45:52 through 2038-01-19 03:14:07 @sc{utc}. Systems with 64-bitsigned @code{time_t} can represent all the times in the knownlifetime of the universe.@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.* Authors of getdate:: 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 the 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 numbers may be written out in words in most contexts. This ismost useful for specifying day of the week items or relative items (seebelow). Here is the list: @samp{first} for 1, @samp{next} for 2,@samp{third} 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. Also, @samp{last} means exactly @math{-1}.@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 @command{date} is 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 dateFri Dec 15 19:48:05 UTC 2000$ TZ=UTC0 date +"%Y-%m-%d %H:%M:%SZ"2000-12-15 19:48:05Z$ date --iso-8601=seconds # a GNU extension2000-12-15T11:48:05-0800$ date --rfc-822 # a GNU extensionFri, 15 Dec 2000 11:48:05 -0800$ date +"%Y-%m-%d %H:%M:%S %z" # %z is a GNU extension.2000-12-15 11:48:05 -0800@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.@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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -