國祚的全自動計算,經納入農曆月的計算後,更加顯而易懂知曉國祚長短。國祚程式對於有志之士,乃具有鼓舞士氣之用途,期正面助益於國祚計算。
資料結構/演算法
<font face="Microsoft YaHei" size=7><b>
<script language="javascript">
var Today = new Date();
var Timezone = (Today.getTimezoneOffset() + 480) / 1440;
var delta, deltaYear, deltaMonth, deltaDay, indexMonth, indexQuantity;
var MonthQuantity = new Array(12, 12, 13, 12, 12, 13, 12, 13, 12);
var Empire = new Array(110);
initialize(Empire);
for (indexMonth = Empire.length; indexMonth >= 0; indexMonth--) {
delta = Today - Empire[indexMonth] + 86400000;
if (delta >= 0) {
deltaYear = 0;
deltaDay = Math.round(delta / 86400000 + Timezone - 0.4999999999);
for (indexQuantity = 0; indexQuantity < MonthQuantity.length; indexQuantity++) {
if (indexMonth - MonthQuantity[indexQuantity] >= 0) {
indexMonth -= MonthQuantity[indexQuantity];
deltaYear++;
} else {
deltaMonth = indexMonth;
break;
}
}
break;
}
}
var deltaYearNumber = Number(deltaYear), deltaMonthNumber = Number(deltaMonth), deltaDayNumber = Number(deltaDay);
var str = "國祚:" + deltaYearNumber + " 年 " + deltaMonthNumber + " 個月又 " + deltaDayNumber + " 日";
document.write(str);
<!------------------------------------------------------------------------------------------------------------------>
function Number(deltaData) {
var NUM_1, NUM_0, deltaNumber;
var NUM = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
NUM_1 = Math.floor(deltaData / Math.pow(10, 1));
NUM_0 = Math.floor(deltaData - NUM_1 * Math.pow(10, 1));
if (NUM_1 >= 1) {
deltaNumber = NUM[NUM_1] + NUM[NUM_0];
} else {
deltaNumber = NUM[NUM_0];
}
return deltaNumber;
}
<!------------------------------------------------------------------------------------------------------------------>
function initialize(NewMonth) {
NewMonth[ 0 ] = new Date(2015, 3,24); NewMonth[ 40] = new Date(2018, 6,18); NewMonth[ 80] = new Date(2021, 9,11);
NewMonth[ 1 ] = new Date(2015, 4,23); NewMonth[ 41] = new Date(2018, 7,16); NewMonth[ 81] = new Date(2021,10,10);
NewMonth[ 2 ] = new Date(2015, 5,21); NewMonth[ 42] = new Date(2018, 8,15); NewMonth[ 82] = new Date(2021,11, 9);
NewMonth[ 3 ] = new Date(2015, 6,21); NewMonth[ 43] = new Date(2018, 9,14); NewMonth[ 83] = new Date(2022, 0, 8);
NewMonth[ 4 ] = new Date(2015, 7,19); NewMonth[ 44] = new Date(2018,10,13); NewMonth[ 84] = new Date(2022, 1, 6);
NewMonth[ 5 ] = new Date(2015, 8,18); NewMonth[ 45] = new Date(2018,11,12); NewMonth[ 85] = new Date(2022, 2, 8);
NewMonth[ 6 ] = new Date(2015, 9,18); NewMonth[ 46] = new Date(2019, 0,11); NewMonth[ 86] = new Date(2022, 3, 6);
NewMonth[ 7 ] = new Date(2015,10,17); NewMonth[ 47] = new Date(2019, 1,10); NewMonth[ 87] = new Date(2022, 4, 6);
NewMonth[ 8 ] = new Date(2015,11,16); NewMonth[ 48] = new Date(2019, 2,12); NewMonth[ 88] = new Date(2022, 5, 4);
NewMonth[ 9 ] = new Date(2016, 0,15); NewMonth[ 49] = new Date(2019, 3,10); NewMonth[ 89] = new Date(2022, 6, 4);
NewMonth[ 10] = new Date(2016, 1,13); NewMonth[ 50] = new Date(2019, 4,10); NewMonth[ 90] = new Date(2022, 7, 3);
NewMonth[ 11] = new Date(2016, 2,14); NewMonth[ 51] = new Date(2019, 5, 8); NewMonth[ 91] = new Date(2022, 8, 1);
NewMonth[ 12] = new Date(2016, 3,12); NewMonth[ 52] = new Date(2019, 6, 8); NewMonth[ 92] = new Date(2022, 9, 1);
NewMonth[ 13] = new Date(2016, 4,12); NewMonth[ 53] = new Date(2019, 7, 6); NewMonth[ 93] = new Date(2022, 9,30);
NewMonth[ 14] = new Date(2016, 5,10); NewMonth[ 54] = new Date(2019, 8, 4); NewMonth[ 94] = new Date(2022,10,29);
NewMonth[ 15] = new Date(2016, 6, 9); NewMonth[ 55] = new Date(2019, 9, 4); NewMonth[ 95] = new Date(2022,11,28);
NewMonth[ 16] = new Date(2016, 7, 8); NewMonth[ 56] = new Date(2019,10, 2); NewMonth[ 96] = new Date(2023, 0,27);
NewMonth[ 17] = new Date(2016, 8, 6); NewMonth[ 57] = new Date(2019,11, 1); NewMonth[ 97] = new Date(2023, 1,25);
NewMonth[ 18] = new Date(2016, 9, 6); NewMonth[ 58] = new Date(2019,11,31); NewMonth[ 98] = new Date(2023, 2,27);
NewMonth[ 19] = new Date(2016,10, 5); NewMonth[ 59] = new Date(2020, 0,30); NewMonth[ 99] = new Date(2023, 3,25);
NewMonth[ 20] = new Date(2016,11, 4); NewMonth[ 60] = new Date(2020, 1,28); NewMonth[100] = new Date(2023, 4,24);
NewMonth[ 21] = new Date(2017, 0, 3); NewMonth[ 61] = new Date(2020, 2,29); NewMonth[101] = new Date(2023, 5,23);
NewMonth[ 22] = new Date(2017, 1, 2); NewMonth[ 62] = new Date(2020, 3,28); NewMonth[102] = new Date(2023, 6,23);
NewMonth[ 23] = new Date(2017, 2, 3); NewMonth[ 63] = new Date(2020, 4,28); NewMonth[103] = new Date(2023, 7,21);
NewMonth[ 24] = new Date(2017, 3, 2); NewMonth[ 64] = new Date(2020, 5,26); NewMonth[104] = new Date(2023, 8,20);
NewMonth[ 25] = new Date(2017, 4, 1); NewMonth[ 65] = new Date(2020, 6,26); NewMonth[105] = new Date(2023, 9,20);
NewMonth[ 26] = new Date(2017, 4,31); NewMonth[ 66] = new Date(2020, 7,24); NewMonth[106] = new Date(2023,10,18);
NewMonth[ 27] = new Date(2017, 5,29); NewMonth[ 67] = new Date(2020, 8,22); NewMonth[107] = new Date(2023,11,18);
NewMonth[ 28] = new Date(2017, 6,28); NewMonth[ 68] = new Date(2020, 9,22); NewMonth[108] = new Date(2024, 1,15);
NewMonth[ 29] = new Date(2017, 7,27); NewMonth[ 69] = new Date(2020,10,20); NewMonth[109] = new Date(2024, 2,15);
NewMonth[ 30] = new Date(2017, 8,25); NewMonth[ 70] = new Date(2020,11,20);
NewMonth[ 31] = new Date(2017, 9,25); NewMonth[ 71] = new Date(2021, 0,18);
NewMonth[ 32] = new Date(2017,10,23); NewMonth[ 72] = new Date(2021, 1,17);
NewMonth[ 33] = new Date(2017,11,23); NewMonth[ 73] = new Date(2021, 2,18);
NewMonth[ 34] = new Date(2018, 0,22); NewMonth[ 74] = new Date(2021, 3,17);
NewMonth[ 35] = new Date(2018, 1,21); NewMonth[ 75] = new Date(2021, 4,17);
NewMonth[ 36] = new Date(2018, 2,22); NewMonth[ 76] = new Date(2021, 5,15);
NewMonth[ 37] = new Date(2018, 3,21); NewMonth[ 77] = new Date(2021, 6,15);
NewMonth[ 38] = new Date(2018, 4,20); NewMonth[ 78] = new Date(2021, 7,13);
NewMonth[ 39] = new Date(2018, 5,19); NewMonth[ 79] = new Date(2021, 8,12);
}
</script>
</b></font>