gpt4 book ai didi

bash - 日期 - bash 中没有前导 0 或空格的月份?

转载 作者:行者123 更新时间:2023-12-03 09:47:43 25 4
gpt4 key购买 nike

有人知道如何显示这样的日期吗?

7-1-2019

我目前有这个将前导 0 添加到月份
$(LC_ALL=nn_NO.UTF-8 date +'%-d-%m-%Y')

像这样
7-01-2019

我在 lynx 转储命令中使用这些

谢谢,
克里斯

最佳答案

您已经删除了当天的填充,为什么不为这个月做同样的事情?

$ date +'%-d-%-m-%Y'
7-1-2019

这是来自 man date 的所有填充修饰符的列表:

By default, date pads numeric fields with zeroes. The following optional flags may follow '%':

- (hyphen) do not pad the field

_ (underscore) pad with spaces

0 (zero) pad with zeros

^ use upper case if possible

# use opposite case if possible

After any flags comes an optional field width, as a decimal number; then an optional modifier, which is either E to use the locale's alternate representations if available, or O to use the locale's alternate numeric symbols if available.

关于bash - 日期 - bash 中没有前导 0 或空格的月份?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54066437/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com