How to subtract 5 minute from date

点点圈 提交于 2019-12-20 03:00:06

问题


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:

2015-10-07 23:55:00

Many thanks


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/33016968/how-to-subtract-5-minute-from-date

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!