简体   繁体   English

Linux 日期对象在指定小时/分钟/秒时表现不同

[英]Linux date objects behaving differently when hour/minute/second are specified

Why does adding one day work differently with the variables $d and $dt below?为什么使用下面的变量$d$dt添加一天的工作方式不同?

Linux version: CentOS 6.8 Linux 版本:CentOS 6.8

If there is some kind of hidden timezone conversion going on with $dt but not with $d ?如果$dt某种隐藏的时区转换而不是$d If so, how do I suppress it?如果是这样,我该如何压制它?

d="2019-04-01"
dt="2019-04-01 01:00:00"
date --date="$d +1 days" +'%Y-%m-%d'

Output: 2019-04-02输出:2019-04-02

date --date="$dt +1 days" +'%Y-%m-%d %H:%M:%S'

Output: 2019-04-01 17:00:00输出:2019-04-01 17:00:00

Just so this question is answered (I couldn't find a duplicate) it was pointed out in the comments that the +1 in +1 days was being interpreted as a UTC offset appended to the date.只是为了回答这个问题(我找不到重复的问题),评论中指出+1 days+1被解释为附加到日期的UTC 偏移量。

The solution is to terminate the date string with a time zone specifier such as Z or UTC so it's recognized as a complete date.解决方案是使用时区说明符(例如ZUTC终止日期字符串,以便将其识别为完整日期。

See info '(coreutils) date invocation' for more details on date specifications.有关日期规范的更多详细信息,请参阅info '(coreutils) date invocation'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM