bash一分钟到5分钟 [英] bash round minutes to 5
本文介绍了bash一分钟到5分钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们有此字符串以干净的格式检索日期和时间.
We have this string to retrieve date and time in clean format.
TIMESTAMP=$(date "+%Y%m%d%H%M")
是否存在一些内联代码,可用于将分钟数舍入为5. 所以如果是12:03,它将变成12:00,如果是12:49,它将变成12:45
Is there some inline code that we can use to round the minute to 5 down. So if it is 12:03 it will make it 12:00 and if it is 12:49 it will be 12:45
谢谢!
推荐答案
为此,您可以从总分钟数中减去5为模的分钟数.要打印出来:
To do this you can subtract the minutes modulo 5 from the total minutes. To print it out:
echo "$(date "+%Y%m%d%H%M") - ($(date +%M)%5)" | bc
要将其保存到变量中:
my_var=$(echo "$(date "+%Y%m%d%H%M") - ($(date +%M)%5)" | bc)
这取决于您现在保留的日期格式字符串-一串数字.
This relies on your date format string remaining as it is now - a string of numbers.
示例输出:
$ date "+%Y%m%d%H%M"
201404010701
$ echo "$(date "+%Y%m%d%H%M") - ($(date +%M)%5)" | bc
201404010700
这篇关于bash一分钟到5分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文