【问题标题】:How to add hours to string in linux?如何在linux中为字符串添加小时数?
【发布时间】:2013-09-13 09:46:04
【问题描述】:

我有一个关于格式化日期的问题。

有没有办法添加一些特定的小时或分钟日期。例如,我会将 who -b 命令中的日期分配给变量,然后将 3 小时添加到该变量。

这可以通过某些命令实现还是更棘手?

【问题讨论】:

    标签: linux date date-format rhel


    【解决方案1】:

    这样的东西可以做到。注意date -d" some date " 的使用,然后我们使用+ 3 hours

    tr -s ' ' 压缩空间。 cut -d ' ' -f4- 从第 4 个字段一直到末尾。

    $ who -b
             system boot  2013-09-13 10:19
    $ date -d"$(who -b | tr -s ' ' | cut -d ' ' -f4-) +3 hours"
    Fri Sep 13 10:19:00 CEST 2013
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-06-18
      • 2019-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-14
      • 2016-07-19
      相关资源
      最近更新 更多