Bash: subtracting 10 mins from a given time

后端 未结 4 1780
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-14 08:02

In a bash script, if I have a number that represents a time, in the form hhmmss (or hmmss), what is the best way of subtracting 10 minutes?

ie, 90000 -> 85000

4条回答
  •  没有蜡笔的小新
    2021-02-14 08:53

    why not just use epoch time and then take 600 off of it?

    $ echo "`date +%s` - 600"| bc; date 
    1284050588
    Thu Sep  9 11:53:08 CDT 2010
    $ date -d '1970-01-01 UTC 1284050588 seconds' +"%Y-%m-%d %T %z"
    2010-09-09 11:43:08 -0500
    

提交回复
热议问题