Windows版用は過去にVisual Studio Basicで作成していましたが、HTMLで作成すればmacOSでも使えるので作成してみました。
Visual Studio Basic_40 西暦に対する十干十二支を計算 2024/11/01
西暦から指定した年の十干十二支を計算。
仕組み(年の干支)
基準としてよく使われるのは・・・
1984年 = 甲子(きのえ・ね)(60年周期の1番目)
十干(10)
甲 乙 丙 丁 戊 己 庚 辛 壬 癸
十二支(12)
子 丑 寅 卯 辰 巳 午 未 申 酉 戌 亥
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>十干十二支計算</title>
<style>
body {
padding: 20px;
max-width: 400px;
margin: auto;
background: black;
color: white;
}
label {
display: block;
margin: 8px 0;
}
input[type="number"] {
width: 60px;
}
</style>
</head>
<body>
<center>
<h3>十干十二支計算</h3>
<label>
西暦:
<input type="number" id="year" value="2026">
</label>
<button onclick="calc()">計算</button>
<p id="result"></p>
<script>
function calc() {
const year =
Number(document.getElementById("year").value);
const jikkan =
["甲","乙","丙","丁","戊","己","庚","辛","壬","癸"];
const junishi =
["子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥"];
const jikkanIndex = (year - 4) % 10;
const junishiIndex = (year - 4) % 12;
const eto = jikkan[jikkanIndex] + junishi[junishiIndex];
document.getElementById("result").textContent =
year + "年の干支は「" + eto + "」です。";
}
</script>
</center>
</body>
</html>
実行した直後のデフォルト設定。
[計算]ボタンで結果が出ます。特に芸はないです。



