Bash date 命令无效日期
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16315544/
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
Bash date command invalid date
提问by Dinesh Subedi
In linux bash when I enter date -d "1986-01-01"it shows error
在 linux bash 中输入date -d "1986-01-01"时显示错误
date: invalid date "1986-01-01"
when date -d "1986-01-02"it works
当date -d "1986-01-02"它工作时
when date -d "1987-01-01"it also works
当date -d "1987-01-01"它也有效时
Why date -d "1986-01-01"shows error in Linux Bash shell.
为什么date -d "1986-01-01"在 Linux Bash shell 中显示错误。
I am using Fedora 16
我正在使用 Fedora 16
回答by nosid
Nepal changed its timezone at the beginning of 1986. The following table is copied from the tzdatapackage:
尼泊尔在1986年初更改了时区。下表是从tzdata包中复制的:
# Zone NAME GMTOFF RULES FORMAT [UNTIL]
Zone Asia/Kathmandu 5:41:16 - LMT 1920
5:30 - IST 1986
5:45 - NPT # Nepal Time
That means that on Jan 1 1986 the time from 00:00:00 to 00:14:59 is not valid. The following two commands show, that the first day of 1986 started with 00:15:00:
这意味着在 1986 年 1 月 1 日,从 00:00:00 到 00:14:59 的时间无效。以下两个命令显示 1986 年的第一天从 00:15:00 开始:
$ TZ=Asia/Kathmandu date -d '1985-12-31 23:59:59' '+%s'
504901799
$ TZ=Asia/Kathmandu date -d '1986-01-01 00:15:00' '+%s'
504901800
So the error message of dateis correct. The date is invalid in this timezone. I am not sure what you are doing with the result of this command. However, you can try to use UTC because all dates are valid and unambiguous in UTC:
所以错误信息date是正确的。日期在此时区无效。我不确定你对这个命令的结果做了什么。但是,您可以尝试使用 UTC,因为所有日期在 UTC 中都是有效且明确的:
$ TZ=UTC date -d '1986-01-01'
Wed Jan 1 00:00:00 UTC 1986
回答by RBH
I think you are using alphabet "O" in upper case instead of number "0" in the command :)
我认为您在命令中使用大写字母“O”而不是数字“0”:)

