// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423 Date.prototype.Format = function (fmt) { var o = { "M+": this.getMonth() + 1,//month月 "d+": this.getDate(),//day日 "h+": this.getHours(),//hour小时 "m+": this.getMinutes(),//minute分钟 "s+": this.getSeconds(),//second秒 "q+": Math.floor((this.getMonth() + 3) / 3),//quarter (of a year)季度 "S": this.getMilliseconds()//millisecond毫秒 }; if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); for (var k in o) if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); return fmt; } var ETL_DAY=new Date(new Date().getTime()-1*24*60*60*1000).Format("yyyyMMdd"); console.log(ETL_DAY);
标签:格式化,Format,fmt,javaScript,length,日期,new,Date,RegExp From: https://www.cnblogs.com/zhangdapangzo/p/17211680.html