Add some specific time while using the linux command “date”

前端 未结 7 1048
误落风尘
误落风尘 2021-01-07 20:18

In linux, date can help me to print the current time. If want to print the current time + 1 hour, what option should I give?

7条回答
  •  误落风尘
    2021-01-07 20:42

    On Linux

    Just use -d (or --date) to do some math with the dates:

    date -d '+1 hour' '+%F %T'
    #    ^^^^^^^^^^^^
    

    For example:

    $ date '+%F %T'
    2013-04-22 10:57:24
    $ date -d '+1 hour' '+%F %T'
    2013-04-22 11:57:24
    #           ^
    

    On Mac OS

    Warning, the above only works on Linux, not on Mac OS.

    On Mac OS, the equivalent command is

    date -v+1H
    

提交回复
热议问题