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

标签 bash date

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

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/

相关文章:

php - 如何只选择大于今天日期和时间的行?

linux - 通过指定行号显示单行?

bash - 使用 awk 从标准输入或文件中读取

java - 比较字符串格式的日期

c# - 如何在 C# 中将字符串解析为 dateTime?

java - Java 中的 Date.parse() 使用安全吗,即使它已被弃用?如果没有,是否有可行的替代方案?

php - 如何在 PHP/MySQL 中存储生日和年龄以便年龄可以每天更新?

linux - xterm 终端中的颜色列表

bash - 为什么有人会在 shell 脚本中使用两个 shebang?

linux - 在 sh 中随机选择一个结果