Calculating time (adding minutes) bash

大城市里の小女人 提交于 2019-11-26 21:36:23

问题


I got stuck in part of the script. I have time: for example "16:00" and duration in minutes like: 410.

Is there any easy way to add those two values? I've tried a lot of combinations with date -d, but can't solve it.


回答1:


Try this (Kysu's version):

date -d "16:00 410 minutes" +'%H:%M'

or this:

date -d "16:00 today + 410 minutes" +'%H:%M'

But do not use this:

date -d "16:00 + 410 minutes" +'%H:%M'   # BAD!

Strange things happen if you omit the word today but keep the +. (I think the + 410 is being parsed as a timezone modifier, and then the minutes is interpreted as "add one minute".)



来源:https://stackoverflow.com/questions/21208473/calculating-time-adding-minutes-bash

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