JS 时间格式化函数
2018-03-19 10:08
309 查看
//时间格式化函数Date.prototype.format = function (format) { 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 "S": this.getMilliseconds() //millisecond } if (/(y+)/.test(format)) format = format.replace(RegExp.$1,(this.getFullYear() + "").substr(4 - RegExp.$1.length)); for (var k in o) if (new RegExp("(" + k + ")").test(format))format = format.replace(RegExp.$1,RegExp.$1.length == 1 ? o[k] :("00" + o[k]).substr(("" + o[k]).length)); return format;}使用方法:
alert( new Date(blog.AddTime).format('yyyy-MM-dd hh-mm-ss') );
返回 如: 1911-11-11 00-00-00 格式
alert( new Date(blog.AddTime).format('yyyy-MM-dd hh-mm-ss') );
返回 如: 1911-11-11 00-00-00 格式
相关文章推荐
- js时间戳格式化成日期格式函数
- js时间格式化函数,支持Unix时间戳
- js时间日期格式化封装函数
- js时间戳格式化函数
- js日期时间格式化函数 支持季度 24/12小时制 周 毫秒(Date扩展)
- js日期时间格式化函数
- JS 时间格式化函数~
- JS时间格式化函数
- js中定义函数格式化时间
- js格式化日期/时间函数
- 原生js获取格式化的时间函数!
- js 格式化时间函数
- JS 时间格式化函数
- js时间格式化函数,支持Unix时间戳
- js格式化时间函数
- js 时间戳 日期格式化 函数
- js时间格式化函数(兼容IOS)
- javascript时间格式format函数,js日期格式化函数
- Js-格式化时间戳函数
- js时间格式化