國祚的全自動計算,有其必要性和需求性,因而撰寫程式以便於求算。臺灣帝國採用農民曆,然而農民曆不具規則性,製作萬年曆卻不免費時,因而乃查閱以便寫入程式。國祚粗估不逾越一甲子,乃以六十年為程式撰寫依據,採取迴圈自後往前搜尋差額,經檢核大於零訂國祚的年和日,並於此同時跳出迴圈和判斷式。國祚程式對於有志之士,乃具有鼓舞士氣之用途,期正面助益於國祚計算。
「var Today=new Date();」,經填寫入臺高祖的駕崩日期,國祚程式將會自動停止於此,但是月份依系統設定要扣1,此乃JavaScript之月份起始值為零。以2016年07月08日為例,其輸入數據為var Today=new Date(2016, 6, 8);。
<font face="Microsoft YaHei" size=7><b>
<script language="javascript">
var Today = new Date();
var Timezone = (Today.getTimezoneOffset() + 480) / 1440;
var delta, deltaYear, deltaDay, indexYear;
var EMPIRE_MAX = 2074, EMPIRE_MIN = 2015;
var Empire = new Array(60);
initialize(Empire);
for (indexYear = EMPIRE_MAX; indexYear >= EMPIRE_MIN; indexYear--) {
delta = Today-Empire[indexYear] + 86400000;
if (delta >= 0) {
deltaYear = indexYear - EMPIRE_MIN;
deltaDay = Math.round(delta / 86400000 + Timezone - 0.4999999999);
break;
}
}
var deltaYearNumber = Number(deltaYear), deltaDayNumber = Number(deltaDay);
var str = "國祚:" + deltaYearNumber + " 年 " + deltaDayNumber + " 日";
document.write(str);
<!------------------------------------------------------------------------------------------------------------------>
function Number(deltaData) {
var NUM_2, NUM_1, NUM_0, deltaNumber;
var NUM = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
NUM_2 = Math.floor(deltaData / Math.pow(10, 2));
NUM_1 = Math.floor((deltaData - NUM_2 * Math.pow(10, 2)) / Math.pow(10, 1));
NUM_0 = Math.floor(deltaData - NUM_2 * Math.pow(10, 2) - NUM_1 * Math.pow(10, 1));
if (NUM_2 >= 1) {
deltaNumber = NUM[NUM_2] + NUM[NUM_1] + NUM[NUM_0];
} else {
if (NUM_1 >= 1) {
deltaNumber = NUM[NUM_1] + NUM[NUM_0];
} else {
deltaNumber = NUM[NUM_0];
}
}
return deltaNumber;
}
<!------------------------------------------------------------------------------------------------------------------>
function initialize(NewYear) {
NewYear[2015] = new Date(2015, 3,24); NewYear[2035] = new Date(2035, 3,13); NewYear[2055] = new Date(2055, 3, 2);
NewYear[2016] = new Date(2016, 3,12); NewYear[2036] = new Date(2036, 3, 2); NewYear[2056] = new Date(2056, 3,20);
NewYear[2017] = new Date(2017, 3, 2); NewYear[2037] = new Date(2037, 3,21); NewYear[2057] = new Date(2057, 3, 9);
NewYear[2018] = new Date(2018, 3,21); NewYear[2038] = new Date(2038, 3,10); NewYear[2058] = new Date(2058, 2,29);
NewYear[2019] = new Date(2019, 3,10); NewYear[2039] = new Date(2039, 2,30); NewYear[2059] = new Date(2059, 3,17);
NewYear[2020] = new Date(2020, 2,29); NewYear[2040] = new Date(2040, 3,16); NewYear[2060] = new Date(2060, 3, 6);
NewYear[2021] = new Date(2021, 3,17); NewYear[2041] = new Date(2041, 3, 6); NewYear[2061] = new Date(2061, 2,27);
NewYear[2022] = new Date(2022, 3, 6); NewYear[2042] = new Date(2042, 3,25); NewYear[2062] = new Date(2062, 3,15);
NewYear[2023] = new Date(2023, 3,25); NewYear[2043] = new Date(2043, 3,15); NewYear[2063] = new Date(2063, 3, 4);
NewYear[2024] = new Date(2024, 3,14); NewYear[2044] = new Date(2044, 3, 3); NewYear[2064] = new Date(2064, 3,22);
NewYear[2025] = new Date(2025, 3, 3); NewYear[2045] = new Date(2045, 3,22); NewYear[2065] = new Date(2065, 3,11);
NewYear[2026] = new Date(2026, 3,22); NewYear[2046] = new Date(2046, 3,11); NewYear[2066] = new Date(2066, 2,31);
NewYear[2027] = new Date(2027, 3,12); NewYear[2047] = new Date(2047, 2,31); NewYear[2067] = new Date(2067, 3,19);
NewYear[2028] = new Date(2028, 2,31); NewYear[2048] = new Date(2048, 3,18); NewYear[2068] = new Date(2068, 3, 7);
NewYear[2029] = new Date(2029, 3,19); NewYear[2049] = new Date(2049, 3, 7); NewYear[2069] = new Date(2069, 2,28);
NewYear[2030] = new Date(2030, 3, 8); NewYear[2050] = new Date(2050, 2,28); NewYear[2070] = new Date(2070, 3,16);
NewYear[2031] = new Date(2031, 3,27); NewYear[2051] = new Date(2051, 3,16); NewYear[2071] = new Date(2071, 3, 5);
NewYear[2032] = new Date(2032, 3,15); NewYear[2052] = new Date(2052, 3, 5); NewYear[2072] = new Date(2072, 3,23);
NewYear[2033] = new Date(2033, 3, 5); NewYear[2053] = new Date(2053, 3,24); NewYear[2073] = new Date(2073, 3,12);
NewYear[2034] = new Date(2034, 3,24); NewYear[2054] = new Date(2054, 3,13); NewYear[2074] = new Date(2074, 3, 1);
}
</script>
</b></font>