/**
* 时间戳转时间
* @param timeNumber : number
* @param {boolean} [onlyDate=false]
* @return {*} : string
*/
export const numberToTime = function (timeNumber, onlyDate) {
function toDou (iNow) {
return iNow < 10 ? '0' + iNow : '' + iNow;
}
if (+timeNumber !== 0) {
let oDate = new Date();
if (timeNumber !== undefined) {
oDate.setTime(timeNumber * 1000);
}
let date = oDate.getFullYear() + '-' + toDou(oDate.getMonth() + 1) + '-' + toDou(oDate.getDate());
if (onlyDate) {
return date;
}
return date + ' ' + toDou(oDate.getHours()) + ':' + toDou(oDate.getMinutes()) + ':' + toDou(oDate.getSeconds());
} else {
// 如果后台传过来是 0,即没有这个时间
return ' - ';
}
};
时间转换 拼接
猜你喜欢
转载自blog.csdn.net/qq_42092177/article/details/104696641
今日推荐
周排行