时间转换 &&金额转换

function formatDate(oldtime) {
    oldtime = oldtime === undefined ? Math.round(new Date().getTime() / 1000) : oldtime;
    let now = Date.parse(new Date()) / 1000;
    let date = new Date(oldtime * 1000);
    // console.log(date);
    let year = date.getFullYear();
    let month = date.getMonth() + 1;
    let day = date.getDate();
    let passtime = now - Number(oldtime);
    // console.log(passtime);
    if (passtime < 30) {
        return `刚刚`;
    } else if (passtime > 30 & passtime < 60) {
        return `1分钟前`;
    } else if (passtime > 60 & passtime < 3600) {
        // console.log(passtime);
        return `${Math.floor(passtime / 60)}分钟前`;
    } else if (passtime > 3600 & passtime < 86400) {
        return `${Math.floor(passtime / 60 / 60)}小时前`;
    } else if (passtime > 86400 & passtime < 172800) {
        return `昨天`;
    } else if (passtime > 172800 & passtime < 604800) {
        return `${Math.floor(passtime / 3600 / 24)}天前`;
    } else if (passtime > 604800 & passtime < 2592000) {
        return `${month}月${day}日`;
    } else if (passtime > 2592000) {
        return `${year}年${month}月${day}日`;
    }
};
 function formatPrice(price) {
    price = Number(price).toFixed(2) + '';
    return price.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
};

你可能感兴趣的:(时间转换 &&金额转换)