[英]Can't increment date with ddmmyyyy format in bash
Why does this: 为什么这样做:
date +%d%m%Y -d "01052018 + 1 day"
error w/ 错误w /
date: invalid date `02062018 + 1 day'
on CentOS 7.3 in CEST? 在CEST中的CentOS 7.3上? I've tried a few variations 我尝试了一些变化
date +%d%m%Y -d "$date 12:00 + 1 day"
date +%d%m%Y -ud "$date UTC + 1 day"
to no avail. 无济于事。 What am I missing? 我想念什么?
GNU date does not support date format ddmmyyyy of type as you can see from Pure numbers in date strings , you need to change it of type yyyymmdd to make it work 从日期字符串的纯数字中可以看到,GNU日期不支持类型的日期格式ddmmyyyyy ,您需要将其更改为yyyymmdd类型以使其起作用
date -d "20180501 + 1 day"
or with UTC as 或使用UTC作为
date -ud "20180501 UTC + 1 day"
If your original string is from a variable and you need a work-around to make it compatible with the format above, do it using parameter expansion 如果您的原始字符串来自变量,并且您需要一种变通方法以使其与上述格式兼容,请使用参数扩展
rawdate="02062018"
compatDate="${rawdate:4}${rawdate:2:2}${rawdate:0:2}"
and use the variable compatDate
in the date
command 并在date
命令中使用变量compatDate
date -d "${compatDate} + 1 day"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.