详细解决方案
js 格式化时隔日期函数
热度:374 发布时间:2012-09-28 00:03:35.0
js 格式化时间日期函数
[代码] [JavaScript]代码
04 |
Date.prototype.format = function (format) {
|
09 |
???????? "M+" : this .getMonth() + 1,
|
10 |
???????? "d+" : this .getDate(),
|
11 |
???????? "h+" : this .getHours(),
|
12 |
???????? "m+" : this .getMinutes(),
|
13 |
???????? "s+" : this .getSeconds(),
|
14 |
???????? "q+" :Math.floor(( this .getMonth() + 3) / 3),
|
15 |
???????? "S" : this .getMilliseconds()
|
19 |
???? if (/(y+)/.test(format)) {
|
20 |
???????? format = format.replace(RegExp.$1, ( this .getFullYear() + "" )
|
21 |
???????????????? .substr(4 - RegExp.$1.length));
|
24 |
???? for ( var k in o) {
|
25 |
???????? if ( new RegExp( "(" + k + ")" ).test(format)) {
|
26 |
???????????? format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k]
|
27 |
???????????????????? : ( "00" + o[k]).substr(( "" + o[k]).length));
|
[代码] 调用方式
1 |
var now = new Date().format( "yyyy-MM-dd hh:mm:ss" ); |