我有这样的输入:
start: 0.21 | duration: 0.30 | text: Subtitle Text 1
start: 0.32 | duration: 0.52 | text: Subtitle Text 2
这个输入需要转换成SRT格式,所以变成了这样:
1
00:00:00,210 --> 00:00:00,300
Subtitle Text 1
2
00:00:00,320 --> 00:00:00,520
Subtitle Text 2
JS:
function formatMilliseconds($milliseconds) {
$seconds = Math.floor($milliseconds / 1000);
$minutes = Math.floor($seconds / 60);
$hours = Math.floor($minutes / 60);
$milliseconds = $milliseconds % 1000;
$seconds = $seconds % 60;
$minutes = $minutes % 60;
console.log( $hours, $minutes, $seconds, $milliseconds); // 0 0 0 0.21
}
格式毫秒(0.21)