我有一个以下数值的电子表格:
1:29.460
我需要将其转换为
89.460
我有大量这些播放偏移量。我可以在Excel中进行转换,也可以使用JavaScript。
任何关于公式的建议都将不胜感激!
我有一个以下数值的电子表格:
1:29.460
我需要将其转换为
89.460
我有大量这些播放偏移量。我可以在Excel中进行转换,也可以使用JavaScript。
任何关于公式的建议都将不胜感激!
以下是一个 JavaScript 解决方案:
function convert(input) {
var parts = input.split(':'),
minutes = +parts[0],
seconds = +parts[1];
return (minutes * 60 + seconds).toFixed(3);
}
convert('1:29.460'); // '89.460'
您可以使用类似以下的代码:
function toSeconds(str) {
var pieces = str.split(":");
var result = Number(pieces[0]) * 60 + Number(pieces[1]);
return(result.toFixed(3));
}
console.log(toSeconds("1:29.460")); // returns 89.460
Public Function ConvertToSecond(r As Range)
Dim arr As Variant, lMinutes As Long, lSeconds As Double
Debug.Print (r.Value)
arr = Split(r.Value, ":")
lMinutes = arr(0)
lSeconds = CDbl(Replace(arr(1), ".", ","))
ConvertToSecond = Format(lMinutes * 60 + lSeconds, "#0.0##")
End Function
Public Function FormatMinutes(ByVal stime) As String
Dim hour: hour = Mid(stime, 1, InStr(1, stime, ":") - 1)
Dim minute: minute = CInt(Mid(stime, InStr(1, stime, ":") + 1, InStr(1, stime, ".") - InStr(1, stime, ":") - 1))
FormatMinutes = (hour * 60 + minute) & Mid(stime, InStr(1, stime, "."), Len(stime))
End Function
使用它,只需在公式中输入=FormatMinute(A1)
。
0:1:29.460
并确保其设置为时间格式。=A1*24*60*60