将秒转换成时间格式 00:00:00

export const timeFilter = (seconds: number) => {
	let ss = Math.floor(seconds)// 秒
	let mm = 0// 分
	let hh = 0// 小时
	if (ss > 60) {
		mm = Math.floor(ss / 60);
		ss = Math.floor(ss % 60);
	}
	if (mm > 60) {
		hh = Math.floor(mm / 60);
		mm = Math.floor(mm % 60);
	}

	let result = ('00' + Math.floor(ss)).slice(-2);
	if (mm > 0)
		result = ('00' + Math.floor(mm)).slice(-2) + ':' + result;
	else
		result = '00:' + result;

	if (hh > 0)
		result = ('00' + Math.floor(hh)).slice(-2) + ':' + result;
	return result;
}

另外一个

export const getLocalTime = (nS: number) => {
	let date = new Date(nS);//如果date为13位不需要乘1000
	let Y = date.getFullYear() + '-';
	let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
	let D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';
	let h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
	let m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
	let s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
	return Y + M + D + h + m + s;
}
    原文作者:jinxiu_
    原文地址: https://blog.csdn.net/weixin_42049536/article/details/87002689
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞