Created
October 14, 2014 10:48
-
-
Save huanggm/9f4c1ef2163b0729cd51 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
function trans(s) { | |
s = s.replace(/-(\d)0/g, "-$1"); | |
var d = ["〇", "一", "二", "三", "四", "五", "六", "七", "八", "九", "", "十", "二十", "三十", "年", "月"]; | |
var r = [], flag = 14, gap = 0, t; | |
for(var i = 0; i < s.length; i ++) { | |
t = s.charAt(i); | |
if(t === "-") { | |
r.push(d[flag++]); | |
gap = 10; | |
} else { | |
r.push(d[+t+gap]); | |
gap = 0; | |
} | |
} | |
return r.join("") + "日"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment