别人写的时间处理方法出处找不到了
使用方法
- 该函数不会匹配符号
- 区分大小写字母
- 不需要的位不需要填写 则正则不会匹配
var time1 = new Date().format("YYYY-MM-dd hh:mm:ss");
我有种预感 不给这个 估计没人会觉得好使(就当最后的容错的, 虽然永远不会用上, 但是忘记后看到了就会很方便的内中)
var date = new Date('1999-02-03')
var date = new Date('1999/02/03')
var date = new Date(917971200000)
Date.prototype.format = function (fmt) { //author: meizz
var o = {
// "Y+" : this.getFullYear(), //年
"y+" : this.getFullYear(), //年
"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;
}