记一下格式化时间算法
function srtTimestamp(params) {
let milliseconds = params;
let seconds = Math.floor(milliseconds / 1000);
let minutes = Math.floor(seconds / 60);
let hours = Math.floor(minutes / 60);
milliseconds = milliseconds % 1000;
seconds = seconds % 60;
minutes = minutes % 60;
return (
(hours < 10 ? '0' : '') +
hours +
':' +
(minutes < 10 ? '0' : '') +
minutes +
':' +
(seconds < 10 ? '0' : '') +
seconds +
',' +
(milliseconds < 100 ? '0' : '') +
(milliseconds < 10 ? '0' : '') +
milliseconds
);
}
function inputToSRT(params, index) {
return (
index +
1 +
'\r\n' +
srtTimestamp(params.startTime) +
' --> ' +
srtTimestamp(params.endTime) +
'\r\n' +
params.text +
'\r\n\r\n'
);
}