zl程序教程

您现在的位置是:首页 >  其他

当前栏目

1.javaScript日期格式化转换

2023-04-18 15:51:55 时间
// (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);