NAME
parse_date - parses a date string into a timespec struct.
SYNOPSIS
#include "timeutils.h"
int parse_date(struct timespec *result, char const *p,
struct timespec const *now)
LDADD libcommon.la
DESCRIPTION
Parse a date/time string, storing the resulting time value into *result.
The string itself is pointed to by *p. Return 1 if successful.
*p can be an incomplete or relative time specification; if so, use
*now as the basis for the returned time.
This function is based upon gnulib's parse-datetime.y-dd7a871.
Below is a plain text version of the gnulib parse-datetime.texi-dd7a871 manual
describing the input strings that are recognized.
Any future modifications to the util-linux parser that affect input strings
should be noted below.
1 Date input formats
********************
First, a quote:
Our units of temporal measurement, from seconds on up to months,
are so complicated, asymmetrical and disjunctive so as to make
coherent mental reckoning in time all but impossible. Indeed, had
some tyrannical god contrived to enslave our minds to time, to
make it all but impossible for 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 or horizontal
surfaces, like a language in which the simplest thought demands
ornate constructions, useless particles and lengthy
circumlocutions. Unlike the more successful patterns of language
and science, which enable us to face experience boldly or at least
level-headedly, our system of temporal calculation silently and
persistently encourages our terror of time.
... It is as though architects had to measure length in feet,
width in meters and height in ells; as though basic instruction
manuals demanded a knowledge of five different languages. It is
no wonder then that we often look into our own immediate past or
future, last Tuesday or a week from Sunday, with feelings of
helpless confusion. ...
--Robert Grudin, `Time and the Art of Living'.
This section describes the textual date representations that GNU
programs accept. These are the strings you, as a user, can supply as
arguments to the various programs. The C interface (via the
`parse_datetime' function) is not described here.
1.1 General date syntax
=======================
A "date" is a string, possibly empty, containing many items separated
by whitespace. The whitespace may be omitted when no ambiguity arises.
The empty string means the beginning of today (i.e., midnight). Order
of the items is immaterial. A date string may contain many flavors of
items:
* calendar date items
* time of day items
* time zone items
* combined date and time of day items
* day of the week items
* relative items
* pure numbers.
We describe each of these item types in turn, below.
A few ordinal numbers may be written out in words in some contexts.
This is most useful for specifying day of the week items or relative
items (see below). Among the most commonly used ordinal numbers, the
word `last' stands for -1, `this' stands for 0, and `first' and `next'
both stand for 1. Because the word `second' stands for the unit of
time there is no way to write the ordinal number 2, but for convenience
`third' stands for 3, `fourth' for 4, `fifth' for 5, `sixth' for 6,
`seventh' for 7, `eighth' for 8, `ninth' for 9, `tenth' for 10,
`eleventh' for 11 and `twelfth' for 12.
When a month is written this way, it is still considered to be
written numerically, instead of being "spelled in full"; this changes
the allowed strings.
In the current implementation, only English is supported for words
and abbreviations like `AM', `DST', `EST', `first', `January',
`Sunday', `tomorrow', and `year'.
The output of the `date' command is not always acceptable as a date
string, not only because of the language problem, but also because
there is no standard meaning for time zone items like `IST'. When using
`date' to generate a date string intended to be parsed later, specify a
date format that is independent of language and that does not use time
zone items other than `UTC' and `Z'. Here are some ways to do this:
$ LC_ALL=C TZ=UTC0 date
Mon Mar 1 00:21:42 UTC 2004
$ TZ=UTC0 date +'%Y-%m-%d %H:%M:%SZ'
2004-03-01 00:21:42Z
$ date --rfc-3339=ns # --rfc-3339 is a GNU extension.
2004-02-29 16:21:42.692722128-08:00
$ date --rfc-2822 # a GNU extension
Sun, 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
Alphabetic case is completely ignored in dates. Comments may be
introduced between round parentheses, as long as included parentheses
are properly nested. Hyphens not followed by a digit are currently
ignored. Leading zeros on numbers are ignored.
Invalid dates like `2005-02-29' or times like `24:00' are rejected.
In the typical case of a host that does not support leap seconds, a
time like `23:59:60' is rejected even if it corresponds to a valid leap
second.
1.2 Calendar date items
=======================
A "calendar date item" specifies a day of the year. It is specified
differently, depending on whether the month is specified numerically or
literally. All these strings specify the same calendar date:
1972-09-24 # 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 1972
24 Sept 72 # September has a special abbreviation.
24 Sep 72 # Three-letter abbreviations always allowed.
Sep 24, 1972
24-sep-72
24sep72
The year can also be omitted. In this case, the last specified year
is used, or the current year if none. For example:
9/24
sep 24
Here are the rules.
For numeric months, the ISO 8601 format `YEAR-MONTH-DAY' is allowed,
where YEAR is any positive number, MONTH is a number between 01 and 12,
and DAY is a number between 01 and 31. A leading zero must be present
if a number is less than ten. If YEAR is 68 or smaller, then 2000 is
added to it; otherwise, if YEAR is less than 100, then 1900 is added to
it. The construct `MONTH/DAY/YEAR', popular in the United States, is
accepted. Also `MONTH/DAY', omitting the year.
Literal months may be spelled out in full: `January', `February',
`March', `April', `May', `June', `July', `August', `September',
`October', `November' or `December'. Literal months may be abbreviated
to their first three letters, possibly followed by an abbreviating dot.
It is also permitted to write `Sept' instead of `September'.
When months are written literally, the calendar date may be given as
any of the following:
DAY MONTH YEAR
DAY MONTH
MONTH DAY YEAR
DAY-MONTH-YEAR
Or, omitting the year:
MONTH DAY
1.3 Time of day items
=====================
A "time of day item" in date strings specifies the time on a given day.
Here are some examples, all of which represent the same time:
20:02:00.000000
20:02
8:02pm
20:02-0500 # In EST (U.S. Eastern Standard Time).
More generally, the time of day may be given as
`HOUR:MINUTE:SECOND', where HOUR is a number between 0 and 23, MINUTE
is a number between 0 and 59, and SECOND is a number between 0 and 59
possibly followed by `.' or `,' and a fraction containing one or more
digits. Alternatively, `:SECOND' can be omitted, in which case it is
taken to be zero. On the rare hosts that support leap seconds, SECOND
may be 60.
If the time is followed by `am' or `pm' (or `a.m.' or `p.m.'), HOUR
is restricted to run from 1 to 12
没有合适的资源?快使用搜索试试~ 我知道了~
util-linux-master
共2000个文件
c:425个
h:120个
err:105个
需积分: 0 0 下载量 173 浏览量
2023-10-04
19:52:16
上传
评论
收藏 14.09MB ZIP 举报
温馨提示
linux工具源码
资源推荐
资源详情
资源评论
收起资源包目录
util-linux-master (2000个子文件)
low-probe-udf-hdd-mkudffs-1.0.0-1 386B
low-probe-udf-hdd-mkudffs-1.0.0-2 407B
COPYING.GPL-3.0-or-later 34KB
COPYING.GPL-2.0-or-later 18KB
COPYING.LGPL-2.1-or-later 26KB
v2.13-ReleaseNotes 21KB
v2.14-ReleaseNotes 18KB
v2.15-ReleaseNotes 29KB
v2.16-ReleaseNotes 8KB
v2.17-ReleaseNotes 22KB
v2.18-ReleaseNotes 21KB
v2.19-ReleaseNotes 29KB
low-probe-udf-hdd-mkudffs-2.2 374B
v2.20-ReleaseNotes 48KB
v2.21-ReleaseNotes 45KB
v2.22-ReleaseNotes 54KB
v2.23-ReleaseNotes 54KB
v2.24-ReleaseNotes 44KB
v2.25-ReleaseNotes 61KB
v2.26-ReleaseNotes 51KB
v2.27-ReleaseNotes 35KB
v2.28-ReleaseNotes 33KB
v2.29-ReleaseNotes 26KB
low-probe-udf-hdd-mkudffs-1.3-1 378B
low-probe-udf-hdd-mkudffs-1.3-2 380B
low-probe-udf-hdd-mkudffs-1.3-3 376B
low-probe-udf-hdd-mkudffs-1.3-4 380B
low-probe-udf-hdd-mkudffs-1.3-5 380B
low-probe-udf-hdd-mkudffs-1.3-6 478B
low-probe-udf-hdd-mkudffs-1.3-7 396B
low-probe-udf-hdd-mkudffs-1.3-8 390B
v2.30-ReleaseNotes 34KB
v2.31-ReleaseNotes 31KB
dump-v2.32 2KB
v2.32-ReleaseNotes 21KB
v2.33-ReleaseNotes 27KB
v2.34-ReleaseNotes 27KB
dump-v2.35 2KB
v2.35-ReleaseNotes 24KB
v2.36-ReleaseNotes 31KB
v2.37-ReleaseNotes 49KB
v2.38-ReleaseNotes 50KB
v2.39-ReleaseNotes 72KB
count.4096 2KB
count.err.4096 170B
low-probe-udf-hdd-udfclient-0.7.5 325B
low-probe-udf-hdd-macosx-2.60-4096 537B
low-probe-udf-bdr-2.60-nero 317B
count.65536 2KB
count.err.65536 170B
low-probe-udf-hdd-udfclient-0.7.7 333B
fsck-images-bug.773892 28B
configure.ac 89KB
addpart 484B
mount.8.adoc 96KB
hwclock.8.adoc 36KB
lsfd.1.adoc 19KB
agetty.8.adoc 19KB
unshare.1.adoc 17KB
getopt.1.adoc 13KB
logger.1.adoc 13KB
blkid.8.adoc 12KB
findmnt.8.adoc 11KB
umount.8.adoc 10KB
script.1.adoc 9KB
login.1.adoc 9KB
cal.1.adoc 9KB
lsblk.8.adoc 9KB
nsenter.1.adoc 8KB
setterm.1.adoc 8KB
dmesg.1.adoc 8KB
fstab.5.adoc 8KB
hardlink.1.adoc 7KB
su.1.adoc 7KB
eject.1.adoc 7KB
losetup.8.adoc 7KB
flock.1.adoc 7KB
pipesz.1.adoc 7KB
setpriv.1.adoc 7KB
lscpu.1.adoc 7KB
runuser.1.adoc 6KB
swapon.8.adoc 6KB
fstrim.8.adoc 6KB
kill.1.adoc 6KB
rtcwake.8.adoc 6KB
uuid_generate.3.adoc 6KB
lslogins.1.adoc 5KB
last.1.adoc 5KB
whereis.1.adoc 5KB
renice.1.adoc 5KB
fallocate.1.adoc 5KB
wipefs.8.adoc 5KB
tunelp.8.adoc 5KB
libblkid.3.adoc 5KB
terminal-colors.d.5.adoc 5KB
readprofile.8.adoc 5KB
scriptreplay.1.adoc 4KB
blkzone.8.adoc 4KB
setarch.8.adoc 4KB
chmem.8.adoc 4KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
平凡上班的咸鱼
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功