批处理之家's Archiver

netdzb 发表于 2020-2-23 12:11

请教shell脚本把时间转换成秒

请教一个shell脚本。
$length="00:01:26.99"
#上面的是个时间长度,如何转成
86.99或者取整到87单位是秒。

red2020 发表于 2020-2-23 14:36

[b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=226714&ptid=54904]1#[/url] [i]netdzb[/i] [/b][code]#!/bin/bash
length="00:01:26.99";
var=$[${length:0:2}*3600+${length:3:2}*60+${length:6:2}+1];
echo $var[/code]

netdzb 发表于 2020-2-23 15:10

[b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=226716&ptid=54904]2#[/url] [i]red2020[/i] [/b]

可以了,谢谢。

页: [1]

Powered by Discuz! Archiver 7.2  © 2001-2009 Comsenz Inc.