Skip to content

Commit

Permalink
修复小时只显示两位数
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Apr 15, 2015
1 parent ae12f59 commit 3a46153
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ new Date('2010-02-02').ago('1987-04-03')
```

### toHHMMSS
> 时间转换
> 时间转换,倒计时 '毫秒'.toHHMMSS(输出格式)
```js
"123112".toHHMMSS('hh时mm分ss秒') //=> 34时11分52秒
Expand Down
13 changes: 9 additions & 4 deletions date.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"q+" : Math.floor((this.getMonth()+3)/3), //quarter
"S" : this.getMilliseconds() //millisecond
}
console.log("ooo",o);
if(/(y+)/.test(format))
format = format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
for(var k in o)
Expand Down Expand Up @@ -80,9 +79,15 @@
"m+":minute,
"s+":second
}
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));
for(var k in o) {
if(new RegExp("("+ k +")").test(format)) {
if(RegExp.$1 == "hh"&&hour>99){
format = format.replace('hh',hour)
}else{
format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length))
}
}
};
return format
}
})(window);

0 comments on commit 3a46153

Please sign in to comment.