Last active
December 20, 2015 19:18
-
-
Save callblueday/6181855 to your computer and use it in GitHub Desktop.
格式化日期,将毫秒转化成字符串的快捷函数
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Format Date | |
* usage: | |
* date2str(new Date(seconds*1000),"MM-dd hh:mm"); | |
*/ | |
date2str = function(x,y) { | |
var z = {M:x.getMonth()+1,d:x.getDate(),h:x.getHours(),m:x.getMinutes(),s:x.getSeconds()}; | |
y = y.replace(/(M+|d+|h+|m+|s+)/g,function(v) { | |
return ((v.length>1?"0":"")+eval('z.'+v.slice(-1))).slice(-2) | |
}); | |
return y.replace(/(y+)/g,function(v) {return x.getFullYear().toString().slice(-v.length)}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment