简体   繁体   中英

Calculating time (adding minutes) bash

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.

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".)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM