计算时间(增加分钟)bash [英] Calculating time (adding minutes) bash
本文介绍了计算时间(增加分钟)bash的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我陷入了剧本的一部分.我有时间:例如"16:00",持续时间以分钟为单位:410.
I got stuck in part of the script. I have time: for example "16:00" and duration in minutes like: 410.
是否有任何简单的方法可以将这两个值相加?我已经尝试了很多与date -d
的组合,但无法解决.
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.
推荐答案
尝试一下(Kysu版本):
Try this (Kysu's version):
date -d "16:00 410 minutes" +'%H:%M'
或者这个:
date -d "16:00 today + 410 minutes" +'%H:%M'
但请勿使用此功能:
date -d "16:00 + 410 minutes" +'%H:%M' # BAD!
如果省略单词today
但保留+
,则会发生奇怪的事情. (我认为+ 410
被解析为时区修饰符,然后minutes
被解释为加一分钟".)
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".)
这篇关于计算时间(增加分钟)bash的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文