A
A
Alexey Medvedev2015-08-10 14:39:00
JavaScript
Alexey Medvedev, 2015-08-10 14:39:00

How to parse the format string 00:00:00.00 into an array of 4 values?

Actually the whole point is in the question itself. There is a time string hours:minutes:seconds.hundredths_of_seconds. You need to parse this value and calculate the total number of milliseconds.
Did it like this:

var tags = '01:10:01.10';
var re = /\s*:\s*/;
var re2 = /\s*.\s*/;
var tagList = tags.split(re);
var tagList2 = tagList['2'].split(re2);
var ms = (parseInt(tagList['0']*3600000))+(parseInt(tagList['1']*60000))+(parseInt(tagList2['0']*1000))+(parseInt(tagList2['1']*10));

And I get something completely wrong...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Burov, 2015-08-10
@medvedhack

tags.split(/[:.]/);

V
Vladimir Martyanov, 2015-08-10
@vilgeforce

Repeat 4 times: read two bytes, enter where necessary. We read 1 more byte, check that it is ":", shift the read position by 3. Add some checks for invalid lines and PROFIT!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question