Bash 命令日期的 -d 选项格式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22450302/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The -d option format of the Bash command date
提问by Sayakiss
In date
's man page:
Indate
的手册页:
-d, --date=STRING display time described by STRING, not 'now'
Sounds like you should input a exact date, but I find date -d "-1 day"
works.
听起来你应该输入一个确切的日期,但我找到了date -d "-1 day"
作品。
I just want a list of the format of -d option
of the command date
. I googled, but find none.
我只想要-d option
命令格式的列表date
。我用谷歌搜索,但没有找到。
回答by fedorqui 'SO stop harming'
From man date
:
来自man date
:
DATE STRING
The --date=STRING is a mostly free format human readable date string such as "Sun, 29 Feb 2004 16:21:42 -0800" or "2004-02-29 16:21:42" or even "next Thursday". A date string may contain items indicating calendar date, time of day, time zone, day of week, relative time, relative date, and numbers. An empty string indicates the beginning of the day. The date string format is more complex than is easily documented here but is fully described in the info documentation.
日期字符串
--date=STRING 是一种大多数自由格式的人类可读日期字符串,例如“Sun, 29 Feb 2004 16:21:42 -0800”或“2004-02-29 16:21:42”甚至“下周四” . 日期字符串可能包含指示日历日期、一天中的时间、时区、星期几、相对时间、相对日期和数字的项目。空字符串表示一天的开始。日期字符串格式比此处容易记录的更复杂,但在信息文档中进行了完整描述。
Then you can get more info and examples typing
然后您可以获得更多信息和示例输入
info date
Which you can find in Date input formats.
您可以在日期输入格式中找到。
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.
日期是一个字符串,可能是空的,包含许多由空格分隔的项目。当没有歧义时,可以省略空格。空字符串表示今天的开始(即午夜)。物品的顺序无关紧要。日期字符串可能包含多种类型的项目:
- 日历日期项目
- 时间项目
- 时区项目
- 组合日期和时间项目
- 星期几项目
- 相关项目
- 纯数字。
回答by trikelef
I will try to list just a collection of what you can use with date -d:
我将尝试仅列出您可以与 date -d 一起使用的集合:
- (last|next) (second|minute|hour|day|month|year)
- X (seconds|minutes|hours|days|months|years) ago, where X=...,-1,0,1,2,3,...
- X (second|minute|hour|day|month|year) , where X=...,-1,0,1,2,3,...
- yesterday, tomorrow
- @XXXXXXXXX, where XXXXXXXX seconds since epoch
- (last|next) (second|minute|hour|day|month|year)
- X(秒|分钟|小时|天|月|年)之前,其中 X=...,-1,0,1,2,3,...
- X (second|minute|hour|day|month|year) ,其中 X=...,-1,0,1,2,3,...
- 昨天,明天
- @XXXXXXXXX,自纪元以来的 XXXXXXXX 秒
回答by SzG
You can access its docs by
您可以通过以下方式访问其文档
man date
You can even do this:
你甚至可以这样做:
date -d yesterday