如何将js日期格式化.txt文件中的日期进行转换?

更新于
2026-09-29 09:55:41
1阅读来源:SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计228个文字,预计阅读时间需要1分钟。

如何将js日期格式化.txt文件中的日期进行转换?

javascript// 简化版日期格式化函数Date.prototype.Format=function(fmt) { var o={ M: this.getMonth() + 1, // 月份 d: this.getDate(), // 日 h: this.getHours(), // 时 m: this.getMinutes(), // 分 s: this.getSeconds() // 秒 }; var week={ 0: 日, 1: 一, 2: 二, 3: 三, 4: 四, 5: 五, 6: 六 }; if(/(M+|d+|h+|m+|s+)/.test(fmt)){ fmt=fmt.replace(RegExp.$1, function(match){ var value=o[match]; if(match==M){ return value <10 ? '0' + value : value; } else if(match==d || match==h || match==m || match==s){ return value < 10 ? '0' + value : value; } else { return value; } }); } return fmt.replace(/(y+)/ig, function(match){ return (this.getFullYear() + '').substr(4 - match.length); }).replace(/(w+)/ig, function(match){ return week[this.getDay()]; });};

js日期格式化.txt

//日期格式化 Date.prototype.Format = function (fmt) { var o = { "M+": this.getMonth() + 1, //月份 "d+": this.getDate(), //日 "h+": this.getHours(), //小时 "m+": this.getMinutes(), //分 "s+": this.getSeconds(), //秒 "q+": Math.floor((this.getMonth() + 3) / 3), //季度 "S": this.getMilliseconds() //毫秒 }; 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; }

如何将js日期格式化.txt文件中的日期进行转换?

本文共计228个文字,预计阅读时间需要1分钟。

如何将js日期格式化.txt文件中的日期进行转换?

javascript// 简化版日期格式化函数Date.prototype.Format=function(fmt) { var o={ M: this.getMonth() + 1, // 月份 d: this.getDate(), // 日 h: this.getHours(), // 时 m: this.getMinutes(), // 分 s: this.getSeconds() // 秒 }; var week={ 0: 日, 1: 一, 2: 二, 3: 三, 4: 四, 5: 五, 6: 六 }; if(/(M+|d+|h+|m+|s+)/.test(fmt)){ fmt=fmt.replace(RegExp.$1, function(match){ var value=o[match]; if(match==M){ return value <10 ? '0' + value : value; } else if(match==d || match==h || match==m || match==s){ return value < 10 ? '0' + value : value; } else { return value; } }); } return fmt.replace(/(y+)/ig, function(match){ return (this.getFullYear() + '').substr(4 - match.length); }).replace(/(w+)/ig, function(match){ return week[this.getDay()]; });};

js日期格式化.txt

//日期格式化 Date.prototype.Format = function (fmt) { var o = { "M+": this.getMonth() + 1, //月份 "d+": this.getDate(), //日 "h+": this.getHours(), //小时 "m+": this.getMinutes(), //分 "s+": this.getSeconds(), //秒 "q+": Math.floor((this.getMonth() + 3) / 3), //季度 "S": this.getMilliseconds() //毫秒 }; 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; }

如何将js日期格式化.txt文件中的日期进行转换?