There are a few times where I find myself liking
01:45
//and
15:00
I believe this time format is HH:MM in military time?
While I have come across some advanced functions that can parse sentences and even include seconds like HH:MM:SS, I am looking for a simple and accurate way to extract just the HH:MM.
So if 15:00 is actually 3:00?
The function below won't work because there's already ":" assuming HHMM, right? But I think I need HH:MM to be parsed correctly?
var getTravelTimeFormatted = function (str) {
var hours = Math.trunc(str / 60),
minutes = str % 60;
return hours + ':' + minutes;
};
Update
So if I assume 15:00 is 3:00, correct?
I removed the ":" and then added it back, but the result is 25.0
, so what does that mean?
var getTravelTimeFormatted = function (str) {
str = str.replace(/:/g,'');
var hours = Math.trunc(str / 60),
minutes = str % 60;
return hours + ':' + minutes;
};
console.log(getTravelTimeFormatted('15:00'));