How to subtract 5 minute from date

前端 未结 2 1774
南笙
南笙 2021-01-22 14:29

I have this data:

`date +%Y-%m-%d`\" 00:00:00\"

that return 2015-10-08 00:00:00

I would like cancel 5 minute:



        
相关标签:
2条回答
  • 2021-01-22 14:59

    You need to subtract 5 minutes from a known point in time:

    $ date -d "00:00:00 today"
    Thu Oct  8 00:00:00 EDT 2015
    $ date -d "00:00:00 today -5 minutes"
    Wed Oct  7 23:55:00 EDT 2015
    

    You just need to add your format string.

    0 讨论(0)
  • 2021-01-22 15:11

    There's more than one way to subtract a value from the current time, although this should match the format shown in your question:

     date -d "-5 min" "+%Y-%m-%d %H:%M:%S"
    

    Result:

    2015-10-08 15:26:13
    
    0 讨论(0)
提交回复
热议问题