干支を求める
説明
干支を求めるには西暦年数から十干と十二支を求め、これらを文字列として連結します。十干は「甲乙丙丁戊己庚辛壬癸」、十二支は「子丑寅卯辰巳午未申酉戌亥」で、これらが60年周期で繰り返されます。
サンプルプログラム
window.onload = function(){
document.getElementById("calcButton").onclick = function(){
var n = document.getElementById("year").value;
document.getElementById("result").innerHTML = calcEto(n);
}
}
function calcEto(year){
var data1 = ["庚","辛","壬","癸","甲","乙","丙","丁","戊","己"];
var data2 = ["申","酉","戌","亥","子","丑","寅","卯","辰","巳","午","未"];
return data1[parseInt(year) % 10] + data2[parseInt(year) % 12];
}