转换HH:MM:SS.mm在庆典秒 [英] Convert HH:MM:SS.mm to seconds in bash
问题描述
我运行产生的形式输出一些GNU时间脚本
毫米:ss.mm(分,秒和毫秒,例如1:20.66)
或HH:MM:SS(小时,分,秒,例如一时43分38秒)。
我想将其转换为秒(以比较它们和图形绘制它们)。
这是要做到这一点使用bash的最简单的方法?
假设你可以运行GNU 日期
命令:
日期+'%s'的-D01:43:38.123
如果脚本生成MM:ss.mm你需要加上00的开头,或日期
将拒绝。 p>
如果你是一个BSD系统(包括Mac OS X),你需要运行日期-j +'%s'的0143.38
除非你有GNU安装日期的MacPorts或家酿或什么的。
I am running some gnu time scripts which generates output of the form mm:ss.mm (minutes, seconds and miliseconds, for example 1:20.66) or hh:MM:ss (hours, minutes and seconds, for example 1:43:38). I want to convert this to seconds (in order to compare them and plot them in a graphic).
Which is the easiest way to do this using bash?
Assuming you can run the GNU date
command:
date +'%s' -d "01:43:38.123"
If the script is generating "mm:ss.mm" you'll need to add "00:" to the beginning, or date
will reject it.
If you're on a BSD system (including Mac OS X), you need to run date -j +'%s' "0143.38"
unless you have GNU date installed with MacPorts or Homebrew or something.
这篇关于转换HH:MM:SS.mm在庆典秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!