js 获取当前日期时间 格式为 yyyy-mm-dd hh:MM:ss
2011-05-17 19:09
1326 查看
Date.prototype.format = function(format){ var args = { "M+" : this.getMonth() + 1, "d+" : this.getDate(), "h+" : this.getHours(), "m+" : this.getMinutes(), "s+" : this.getSeconds(), "q+" : Math.floor((this.getMonth() + 3) / 3), //quarter
"S" : this.getMilliseconds() }; if(/(y+)/.test(format)) format = format.replace(RegExp.$1,(this.getFullYear() + "").substr(4 - RegExp.$1.length)); for(var i in args) { var n = args[i]; if(new RegExp("("+ i +")").test(format)) format = format.replace(RegExp.$1,RegExp.$1.length == 1 ? n : ("00" + n).substr(("" + n).length)); } return format;};
调用方法
alert(new Date().format("YYYY-MM-dd hh:mm:ss:S"));
"S" : this.getMilliseconds() }; if(/(y+)/.test(format)) format = format.replace(RegExp.$1,(this.getFullYear() + "").substr(4 - RegExp.$1.length)); for(var i in args) { var n = args[i]; if(new RegExp("("+ i +")").test(format)) format = format.replace(RegExp.$1,RegExp.$1.length == 1 ? n : ("00" + n).substr(("" + n).length)); } return format;};
调用方法
alert(new Date().format("YYYY-MM-dd hh:mm:ss:S"));
相关文章推荐
- js 获取当前日期时间 格式为 yyyy-mm-dd hh:MM:ss
- js获取当前的日期时间 格式“yyyy-MM-dd HH:MM:SS”
- js获取当前日期,并且转化为时间格式“yyyy-MM-dd HH:MM:SS”
- js 获取当前日期时间 格式为 yyyy-mm-dd hh:MM:ss
- JS获取当前的日期时间 格式“yyyy-MM-dd HH:MM:SS” 可以根据需求修改
- js 获取当前日期时间 格式为 yyyy-mm-dd hh:MM:ss
- js 获取当前日期时间 格式为 yyyy-mm-dd hh:MM:ss
- js获取当前日期时间“yyyy-MM-dd HH:MM:SS”
- js获取当前日期时间“yyyy-MM-dd HH:MM:SS”
- js如何取当前日期时间/格式为:yyyy-mm-dd hh:mm:ss
- js获取当前时间与传入的时间进行比较 格式yyyy-MM-dd hh:mm:ss
- js获取当前日期时间“yyyy-MM-dd HH:MM:SS”
- 获取当前的日期时间 格式“yyyy-MM-dd HH:MM:SS”
- js获取当前时间和获取前N天 格式:yyyy-MM-dd HH:mm:ss
- js获取当前日期时间“yyyy-MM-dd HH:MM:SS”
- 获取当前的日期时间 格式“yyyy-MM-dd HH:MM:SS"
- js获取当前日期时间“yyyy-MM-dd HH:MM:SS”
- js获取当前日期时间“yyyy-MM-dd HH:MM:SS”
- js获取当前日期时间“yyyy-MM-dd HH:MM:SS”
- js中怎么获取系统当前时间 格式 yyyy-MM-dd HH:MM:SS