JavaScript格式化显示日期
2017-09-29 15:03
411 查看
Date.prototype.Format = function(fmt) { var o = { "M+" : this.getMonth()+1, //月份 "d+" : this.getDate(), //日 "h+" : this.getHours()%12 == 0 ? 12 : this.getHours()%12, //小时 "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; }
console.log(new Date().Format("yyyy-MM-dd HH:mm:ss"));
相关文章推荐
- javascript 格式化日期显示
- 如何使用Javascript格式化日期显示
- 如何使用Javascript格式化日期显示
- 如何使用Javascript格式化日期显示
- javascript 格式化 日期
- JavaScript-日期格式化(一)
- javascript日期对象格式化为字符串的实现方法
- 常用的javascript日期格式化
- android 字符串工具类 格式化日期字符串 拼接数组 判断字符串是否为空 转换时间显示 转换文件大小 获取中英文字符个数
- 给 Javascript 的 日期(Date)对象扩展一个格式化(format)方法
- javascript 日期格式化(转)
- javascript扩展date对象格式化日期时间输出(二)
- JavaScript自定义日期格式化函数
- Asp.net日期字符串格式化显示--DateTime.ToString()用法详解
- javascript Date format(js日期格式化)
- javascript 日期格式化
- javascript动态显示日期时间
- Javascript 日期格式化
- [转]javascript Date format(js日期格式化)
- Javascript日期格式化