我有开始日期,时间和结束日期,时间以及我正在查找的总旅行时间。输出以毫秒为单位,我需要将其转换为小时格式。通过在这里搜索其他答案,我尝试了以下但没有结果。将毫秒转换为小时格式
<md-cell *mdCellDef="let row"> {{row?.duration | formatDuration}} </md-cell>
和TS文件:
export class StoppageComponent implements OnInit {
constructor() {
}
ngOnInit() {
}
filter('formatDuration', function() {
return function (input) {
var totalHours, totalMinutes, totalSeconds, hours, minutes, seconds, result='';
totalSeconds = input/1000;
totalMinutes = totalSeconds/60;
totalHours = totalMinutes/60;
seconds = Math.floor(totalSeconds) % 60;
minutes = Math.floor(totalMinutes) % 60;
hours = Math.floor(totalHours) % 60;
if (hours !== 0) {
result += hours+':';
if (minutes.toString().length == 1) {
minutes = '0'+minutes;
}
}
result += minutes+':';
if (seconds.toString().length == 1) {
seconds = '0'+seconds;
}
result += seconds;
return result;
};
});
}
我认为错误是与TS文件,因为我在新的角度。
是否有任何使用管道而不使用函数的直接转换?