'Using Luxon, what is the best way to convert a duration into a countdown with the following format T-HH:MM:SS?
I am piping a time value that looks like this PT43H22M15S for example through some array methods so that as it counts it can come out the other side looking like this 43:22:15. The way I do this is like this ...
return this.millisRemaining$.pipe(
map((val) => {
console.log(val);
const duration = Duration.fromMillis(val);
console.log(duration);
const result = duration
.shiftTo('hours', 'minutes', 'seconds')
.toString();
console.log(result);
return result;
}),
map((val) => {
console.log(`from tap: ${val}`);
const slicedVal = val.slice(2);
console.log(slicedVal);
const replacedVal = slicedVal
.replace('H', ':')
.replace('M', ':')
.replace('S', '');
console.log(replacedVal);
return replacedVal;
})
);
}
however, I have an issue. Lets say I want to start with 43 Hours. The output will be 43: and if the preceding number is a 0 it will not show up. like :11 ... :10 ... :9 ...etc
How do I get it to display 43:00:00 and :09 ... :08 etc?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
