Skip to content

Instantly share code, notes, and snippets.

@huanggm
Created October 14, 2014 10:48
Show Gist options
  • Save huanggm/9f4c1ef2163b0729cd51 to your computer and use it in GitHub Desktop.
Save huanggm/9f4c1ef2163b0729cd51 to your computer and use it in GitHub Desktop.
将给定的年月日由数字转为汉字
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