js一些格式化
/* 格式化金额 */
function formatAmount(s, n) {
n = n > 0 && n <= 20 ? n : 2;
s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
var l = s.split(".")[0].split("").reverse(), r = s.split(".")[1];
t = "";
for (i = 0; i < l.length; i++) {
//t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
t += l[i];
}
return t.split("").reverse().join("") + "." + r;
}
/*将时间戳转换为日期格式*/
function parseDate(obj){
var test = new Date(parseInt(obj) * 1000);
var $_year = test.getFullYear();
var $_month = parseInt(test.getMonth())+1;
var $_day = test.getDate();
var $_f_date = $_year +"-"+$_month+"-"+$_day;
return $_f_date;
}