Trying to calculate the duration between two dates in TypeScript (Angular): 2021-11-19 21:59:59
and 2021-11-19 22:00:18
let startDate: Date = new Date(start);
let endDate: Date = new Date(end);
if(end != null) {
let duration = new Date(endDate.getTime() - startDate.getTime());
return duration.getHours() + ":" + duration.getMinutes() + ":" + duration.getSeconds();
} else {
return "";
}
However, the resulting time is incorrect: 1:0:19
.
I am aiming for 00:00:19
EDIT
Tried the following but the result remains incorrect: 01:00:19
const datepipe: DatePipe = new DatePipe('en-US')
let formattedDate = datepipe.transform(duration, 'HH:mm:ss')