Skip to content

Commit

Permalink
时间转换,倒计时
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Apr 14, 2015
1 parent 1962b52 commit ae12f59
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@ new Date('2010-02-02').ago('1987-04-03')
//=> "23年前"
```

### toHHMMSS
> 时间转换
```js
"123112".toHHMMSS('hh时mm分ss秒') //=> 34时11分52秒
```
25 changes: 25 additions & 0 deletions date.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"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 @@ -60,4 +61,28 @@
else result="刚刚";
return result;
}
/**
* [toHHMMSS 超过分钟以分钟为单位,超过小时以小时为单位]
* @param {[type]} format ["123112".toHHMMSS('hh时mm分ss秒')]
* @return {[type]} [number]
*/
String.prototype.toHHMMSS = function(format) {
var str = this.replace(/^\s\s*/, ''),hour, minute, second,o;
if(!str.length&&str.length>0) return '';
str = parseInt(str)

hour = parseInt(str/3600)
minute = parseInt(str/60)
if(minute>=60) minute=minute%60
second = str % 60;
o = {
"h+":hour,
"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));
return format
}
})(window);

0 comments on commit ae12f59

Please sign in to comment.