//格式化数字 function toStringNum(data,n,s){ n = n||3; s = s||','; if(data){ var dataArray = (data+'').split(''); var show = ""; for(var j=1,i=dataArray.length-1;i>=0;i--){ show = dataArray[i]+show; if(j++%n == 0 && i>0){ show = s+show; } } return show; } return ''; } toStringNum(dataAll.ajs.VALUE,3,',');//23,432
//格式化日期 function dateFormat(fmt, date) { let ret; let week = ['日','一','二','三','四','五','六'] const opt = { "Y+": date.getFullYear().toString(), // 年 "m+": (date.getMonth() + 1).toString(), // 月 "d+": date.getDate().toString(), // 日 "H+": date.getHours().toString(), // 时 "M+": date.getMinutes().toString(), // 分 "S+": date.getSeconds().toString(), // 秒 "w+": date.getDay().toString(), // 周 "W+": week[date.getDay()].toString() // 周 // 有其他格式化字符需求可以继续添加,必须转化成字符串 }; for (let k in opt) { ret = new RegExp("(" + k + ")").exec(fmt); if (ret) { fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0"))) }; }; return fmt; } dateFormat('YYYY年mm月dd日 星期W HH:MM:SS',new Date());
/** * String.padStart() * version 1.0.1 * Feature Chrome Firefox Internet Explorer Opera Safari Edge * Basic support 57 51 (No) 44 10 15 * ------------------------------------------------------------------------------- */ if (!String.prototype.padStart) { String.prototype.padStart = function padStart(targetLength, padString) { targetLength = targetLength >> 0; //floor if number or convert non-number to 0; padString = String(typeof padString !== 'undefined' ? padString : ' '); if (this.length > targetLength) { return String(this); } else { targetLength = targetLength - this.length; if (targetLength > padString.length) { padString += padString.repeat(targetLength / padString.length); //append to original to ensure we are longer than needed } return padString.slice(0, targetLength) + String(this); } }; }