// 格式化js时间 $.FormatDateTime = function (obj, IsMi) { var myDate = new Date(obj); var year = myDate.getFullYear(); var month = ("0" + (myDate.getMonth() + 1)).slice(-2); var day = ("0" + myDate.getDate()).slice(-2); var h = ("0" + myDate.getHours()).slice(-2); var m = ("0" + myDate.getMinutes()).slice(-2); var s = ("0" + myDate.getSeconds()).slice(-2); var mi = ("00" + myDate.getMilliseconds()).slice(-3); if (IsMi == true) { return year + "-" + month + "-" + day + " " + h + ":" + m + ":" + s; } else { return year + "-" + month + "-" + day + " " + h + ":" + m + ":" + s + "." + mi; } }; // 格式化金额 $.FormatMoney = function($cell) { var reg = /[\$,%]/g; var key = parseFloat( String($cell).replace(reg, '')).toFixed(2); // toFixed小数点后两位 return isNaN(key) ? 0.00 : key; }; // for example var obj = "2012-11-21 16:39:44.767739"; $.FormatDateTime(obj, false); var cell = "5.0000$"; $.FormatMoney(cell);