我已经构建了这个函数,将时间从timeStamp表单转换为小时表单,但结果显示了一个数字的时间.... 例如(420> 7 am)我想表现出像(07 am)
convertTime(time: number) {
let hours: number = Math.floor(time / 60);
let minutes: number = time % 60;
if (hours <= 12) return hours + ':' + minutes + ' am';
else return (hours - 12 ) + ':' + minutes + ' pm';
}
答案 0 :(得分:0)
convertTime(time: number) {
let hours: number = Math.floor(time / 60);
let minutes: number = time % 60;
if (hours <= 12 && hours >=10) return hours + ':' + minutes + ' am';
else if(hours < 10) return '0' + hours + ':'+ minutes +' am';
else return (hours - 12 ) + ':' + minutes + ' pm';
}