js 数字日期格式转换 - xiaofangne

时间:2024-03-06 20:06:44

js 数字日期格式转换

changeDateFormat: function (cellval) {
var dateVal = cellval + "";
if (cellval != null) {
var date = new Date(parseInt(dateVal.replace("/Date(", "").replace(")/", ""), 10));
var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();

return date.getFullYear() + "-" + month + "-" + currentDate + " " ;
}
},
FormatMoney: function (money) {
if (money && money != null) {
money = String(money);
var left = money.split(\'.\')[0], right = money.split(\'.\')[1];
right = right ? (right.length >= 2 ? \'.\' + right.substr(0, 2) : \'.\' + right + \'0\') : \'.00\';
var temp = left.split(\'\').reverse().join(\'\').match(/(\d{1,3})/g);
return (Number(money) < 0 ? "-" : "") + temp.join(\',\').split(\'\').reverse().join(\'\') + right;
} else if (money === 0) { //注意===在这里的使用,如果传入的money为0,if中会将其判定为boolean类型,故而要另外做===判断
return \'0.00\';
} else {
return "";
}
},