美文网首页
Linux shell如何显示RFC1123格式时间

Linux shell如何显示RFC1123格式时间

作者: CodingCode | 来源:发表于2020-02-14 07:34 被阅读0次

    Linux shell如何显示RFC1123格式时间

    $ env TZ=UTC date  '+%a, %d %b %Y %T %Z'
    Thu, 13 Feb 2020 23:30:07 UTC
    $ env TZ=GMT date  '+%a, %d %b %Y %T %Z'
    Thu, 13 Feb 2020 23:30:13 GMT
    

    UTC和GMT是同义词

    另外如果要做简单运算:
    比如前一个小时,后一个小时这些:

    #!/bin/bash
    
    now=$(date +%s)
    env TZ=UTC date --date "@${now}" '+%a, %d %b %Y %T %Z'
    
    (( now -= 3600 ))
    env TZ=UTC date --date "@${now}" '+%a, %d %b %Y %T %Z'
    
    (( now += 3600 * 2))
    env TZ=UTC date --date "@${now}" '+%a, %d %b %Y %T %Z'
    

    运行结果:

    Thu, 13 Feb 2020 23:31:52 UTC
    Thu, 13 Feb 2020 22:31:52 UTC
    Fri, 14 Feb 2020 00:31:52 UTC
    

    相关文章

      网友评论

          本文标题:Linux shell如何显示RFC1123格式时间

          本文链接:https://www.haomeiwen.com/subject/roorfhtx.html