I want to convert the format example '00: 30: 00' on seconds. This is my way. Is there a way to add these values in the 'template string'?
expected effect:
convert1000('00:30:00') --> 1800
convert1000('00:00:10') --> 10
convert1000('00:08:10') --> 490
convert1000('01:01:10') --> 3670
const convert1000 = (time) => {
const [hour, minute, sec] = time.split(':');
if (hour !== "00") {
return `${(hour* 3600)} + ${(minute * 60)} + ${(sec)}`;
}
if (minute !== "00") {
return `${minute * 60} + ${sec} `;
}
return `${sec} `;
}
Use asSeconds
from momentjs duration objects
moment.duration('00:30:00').asSeconds();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With