最常用的小函数

// 是不是数字
function isNumber(n) {
    return (isNaN(n) || isNaN(parseFloat(n, 10))) ? false : true;
}
// 分转元 10000 -> 10.00
function f2y(n) {
    if (isNaN(n) || isNaN(parseFloat(n, 10))) {
        return '-';
    }
    else {
        if (Number(n) === 0) {
            return 0;
        }
        else {
            return (n / 100).toFixed(2);
        }
    }
}
// 时间戳格式化 2016-11-22
function formatDate(n) {
    if (isNaN(n) || isNaN(parseFloat(n, 10))) {
        return '-';
    }

    var oDate = new Date(parseInt(n, 10));
    var y = oDate.getFullYear(),
        d = oDate.getDate() < 10 ? '0' + oDate.getDate() : oDate.getDate(),
        m = (oDate.getMonth() + 1) < 10 ? '0' + (oDate.getMonth() + 1) : (oDate.getMonth() + 1);
    return '' + y + '-' + m + '-' + d;
}
原文地址:https://www.cnblogs.com/shanchenba/p/5625052.html