最近在研究js,看到一个工具比较新颖,在线计算退休时间、退休年龄的工具,如下:http://www.chinawe.net/tools/tuixiunianling/
可以自定义时间和退休年龄,还能得出工作天数。
这个其实就是通过js计算出来的,下面将js代码附上
function y2k(number){
return (number < 1000) ? number + 1900 : number;
}
function daysElapsed(date1,date2){
var difference =
Date.UTC(y2k(date1.getYear()),date1.getMonth(),date1.getDate(),0,0,0)
- Date.UTC(y2k(date2.getYear()),date2.getMonth(),date2.getDate(),0,0,0);
return difference/1000/60/60/24;
}
function HowManyDays(){
var m = document.retire.MyMonth.options[document.retire.MyMonth.selectedIndex].value;
var d = document.retire.MyDay.options[document.retire.MyDay.selectedIndex].value;
var y = document.retire.MyYear.options[document.retire.MyYear.selectedIndex].value;
var birthdate = new Date(y,m,d);
var retireage = document.retire.age.options[document.retire.age.selectedIndex].value * 1;
var mo = 0;
if (retireage != Math.round(retireage)){
retireage = Math.floor(retireage);
mo = 6;
}
var retiredate = new Date(y2k(birthdate.getYear()) + retireage, birthdate.getMonth() + mo, birthdate.getDate());
var months = new Array('涓€鏈�','浜屾湀','涓夋湀',
'鍥涙湀','浜旀湀','鍏湀','涓冩湀','鍏湀','涔濇湀',
'鍗佹湀','鍗佷竴鏈�','鍗佷簩鏈�');
var day = retiredate.getDate();
var month = months[retiredate.getMonth()];
var year = y2k(retiredate.getYear());
var numdays = daysElapsed(retiredate, new Date());
document.retire.oretiredate.value = year + '骞� '+ month + ' ' + day + '鏃�';
document.retire.oretiredays.value = numdays + '澶�';
document.retire.oworkdays.value = Math.round(numdays * 5 / 7) + '澶�';
}
还有其他工具也是的,例如
js代码如下:
function CalculatePre(type) {
time = $("#"+type).val();
iYear = parseInt(time.split("-")[0]);
iMonth = parseInt(time.split("-")[1]);
iDay = parseInt(time.split("-")[2]);
if(!chkDate(time)){
alert("鏃ユ湡鏍煎紡杈撳叆鏈夎锛屼緥濡�2018-11-11");
$("#"+type).focus();
return false;
}
if(!iYear || !iMonth || !iDay){
alert("鏃ユ湡鏍煎紡杈撳叆鏈夎锛屼緥濡�2018-11-11");
$("#"+type).focus();
return false;
}
if(type == 'LastPer'){
average = $("#averagePer").val();
if(!average){
alert("璇烽€夋嫨骞冲潎鏈堢粡鍛ㄦ湡");
$("#averagePer").focus();
return false;
}
perior = 280+parseInt(average)-28;
ov = DateAdd(iMonth+'/'+iDay+'/'+iYear,parseInt(average)-28);
ovTime = ov.getFullYear()+'-'+(ov.getMonth()+1) +'-'+ ov.getDate();
}
PreDay = DateAdd(iMonth+'/'+iDay+'/'+iYear,perior);
$("#Result"+type).val(PreDay.getFullYear()+'骞�'+ (PreDay.getMonth()+1)+'鏈�'+PreDay.getDate()+'鏃�');
now = new Date();
now1 = now.getFullYear()+'-'+ (now.getMonth()+1)+'-'+now.getDate();
betweenday = daysBetween(PreDay.getFullYear()+'-'+(PreDay.getMonth()+1)+'-'+PreDay.getDate(),now1);
if(betweenday>0) {
$('#Result'+type+'Day').val(betweenday);
week = parseInt(daysBetween(now1,ovTime)/7)+1;
if(week>0 && betweenday<266 ) {
$("#P"+type+'Day').val(week);
$("#W"+type).show();
} else {
$("#W"+type).hide();
}
$("#daybetween"+type).show();
} else {
$("#W"+type).hide();
$("#daybetween"+type).hide();
}
$("#"+type+'R').show();
}
function DateAdd(time,Number) {
return new Date(Date.parse(time)+(86400000*Number));
}
function daysBetween(DateOne,DateTwo) {
var OneYear = parseInt(DateOne.split("-")[0]);
var OneMonth = parseInt(DateOne.split("-")[1]);
var OneDay = parseInt(DateOne.split("-")[2]);
var TwoYear = parseInt(DateTwo.split("-")[0]);
var TwoMonth = parseInt(DateTwo.split("-")[1]);
var TwoDay = parseInt(DateTwo.split("-")[2]);
var cha = ((Date.parse(OneMonth+'/'+OneDay+'/'+OneYear)-Date.parse(TwoMonth+'/'+TwoDay+'/'+TwoYear))/86400000);
return cha;
}
function ShowMorePre() {
$('#morePre').show();
$('#morePre1').show();
}
function chkDate(sDate) {
var r = /\d{4}(?:-\d{1,2}){0,2}/
//姝e垯琛ㄨ揪寮忥紝鍒ゆ柇鏄惁涓簓yyy-mm-dd,yyyy-mm,yyyy鏍煎紡
if(sDate.match(r) == sDate) {
var arr = sDate.split("-")
switch(arr.length) {
//鏍规嵁涓嶅悓鐨剏yyy-mm-dd,yyyy-mm鏍煎紡鍒ゆ柇骞存湀鏃ユ暟瀛楁槸鍚︽纭�
case 3:
arr[1]=arr[1]-1;
var tmpDate=new Date(arr[0],arr[1],arr[2]);
if(tmpDate.getMonth()==arr[1] && tmpDate.getFullYear()==arr[0]) return true;
break;
case 2:
if(arr[1]<13) return true;
break;
default:
return false;
}
}
return false;
}
var ydate;
function fGetDaysInMonth(iMonth, iYear) {
var dPrevDate = new Date(iYear, iMonth, 0);
return dPrevDate.getDate();
}
function fBuildCal(iYear,iMonth,LastP,ThisP,NextP,LastY,ThisY,NextY) {
colorBg = new Array();
colorBg[0] = new Array(7);
colorBg[1] = new Array(7);
colorBg[2] = new Array(7);
colorBg[3] = new Array(7);
colorBg[4] = new Array(7);
colorBg[5] = new Array(7);
colorBg[6] = new Array(7);
var aMonth = new Array();
aMonth[0] = new Array(7);
aMonth[1] = new Array(7);
aMonth[2] = new Array(7);
aMonth[3] = new Array(7);
aMonth[4] = new Array(7);
aMonth[5] = new Array(7);
aMonth[6] = new Array(7);
var dCalDate = new Date(iYear, iMonth-1, 1);
var LP= new Array();
var TP= new Array();
var NP= new Array();
var LY= new Array();
var TY= new Array();
var NY= new Array();
var iDayOfFirst = dCalDate.getDay();
var iDaysInMonth = fGetDaysInMonth(iMonth, iYear);
var iVarDate = 1;
var i, d, w;
aMonth[0][0] = "鏃�";
aMonth[0][1] = "涓€";
aMonth[0][2] = "浜�";
aMonth[0][3] = "涓�";
aMonth[0][4] = "鍥�";
aMonth[0][5] = "浜�";
aMonth[0][6] = "鍏�";
LP[0] = parseInt(LastP['s'].getFullYear()*10000+(LastP['s'].getMonth()+1)*100+LastP['s'].getDate());
LP[1] = parseInt(LastP['e'].getFullYear()*10000+(LastP['e'].getMonth()+1)*100+LastP['e'].getDate());
TP[0] = parseInt(ThisP['s'].getFullYear()*10000+(ThisP['s'].getMonth()+1)*100+ThisP['s'].getDate());
TP[1] = parseInt(ThisP['e'].getFullYear()*10000+(ThisP['e'].getMonth()+1)*100+ThisP['e'].getDate());
NP[0] = parseInt(NextP['s'].getFullYear()*10000+(NextP['s'].getMonth()+1)*100+NextP['s'].getDate());
NP[1] = parseInt(NextP['e'].getFullYear()*10000+(NextP['e'].getMonth()+1)*100+NextP['e'].getDate());
LY[0] = parseInt(LastY['s'].getFullYear()*10000+(LastY['s'].getMonth()+1)*100+LastY['s'].getDate());
LY[1] = parseInt(LastY['e'].getFullYear()*10000+(LastY['e'].getMonth()+1)*100+LastY['e'].getDate());
TY[0] = parseInt(ThisY['s'].getFullYear()*10000+(ThisY['s'].getMonth()+1)*100+ThisY['s'].getDate());
TY[1] = parseInt(ThisY['e'].getFullYear()*10000+(ThisY['e'].getMonth()+1)*100+ThisY['e'].getDate());
NY[0] = parseInt(NextY['s'].getFullYear()*10000+(NextY['s'].getMonth()+1)*100+NextY['s'].getDate());
NY[1] = parseInt(NextY['e'].getFullYear()*10000+(NextY['e'].getMonth()+1)*100+NextY['e'].getDate());
for (d = iDayOfFirst; d < 7; d++) {
aMonth[1][d] = iVarDate;
value = iVarDate+iMonth*100+iYear*10000;
if((LP[0] <= value && LP[1] >=value) || (TP[0] <= value && TP[1] >=value) || (NP[0] <= value && NP[1] >=value))
colorBg[1][d] = 'class="date_3" title="杩欐槸鎺掑嵉鏈燂紝鎬х敓娲诲彈瀛曞彲鑳芥€уぇ" bgcolor="#ED1B23"';
else if((LY[0] <= value && LY[1] >=value) || (TY[0] <= value && TY[1] >=value) || (NY[0] <= value && NY[1] >=value))
colorBg[1][d] = 'class="date_1" title="杩欐槸鏈堢粡鏈燂紝娉ㄦ剰缁忔湡鍗敓锛岃閬垮厤鎬х敓娲�" bgcolor="#FAA619"';
else colorBg[1][d] = 'class="date_2" title="杩欐槸瀹夊叏鏈燂紝鎬х敓娲讳竴鑸笉鍙楀瓡" bgcolor="#17A40C"';
iVarDate++;
}
for (w = 2; w < 7; w++) {
for (d = 0; d < 7; d++) {
if (iVarDate <= iDaysInMonth) {
value = iVarDate+iMonth*100+iYear*10000;
aMonth[w][d] = iVarDate;
if((LP[0] <= value && LP[1] >=value) || (TP[0] <= value && TP[1] >=value) || (NP[0] <= value && NP[1] >=value))
colorBg[w][d] = 'class="date_3" title="杩欐槸鎺掑嵉鏈燂紝鎬х敓娲诲彈瀛曞彲鑳芥€уぇ" bgcolor="#ED1B23"';
else if((LY[0] <= value && LY[1] >=value) || (TY[0] <= value && TY[1] >=value) || (NY[0] <= value && NY[1] >=value))
colorBg[w][d] = 'class="date_1" title="杩欐槸鏈堢粡鏈燂紝娉ㄦ剰缁忔湡鍗敓锛岃閬垮厤鎬х敓娲�" bgcolor="#FAA619"';
else colorBg[w][d] = 'class="date_2" title="杩欐槸瀹夊叏鏈燂紝鎬х敓娲讳竴鑸笉鍙楀瓡" bgcolor="#17A40C" ';
iVarDate++;
}
}
}
return aMonth;
}
function fDrawCal(iYear, iMonth,myMonth,element) {
var calendar_str;
calendar_str = '<table ';
if(element=='calendar2')calendar_str += 'style="left:340px"';
calendar_str += 'class="date" border="0" cellpadding="0" cellspacing="0">';
calendar_str += "<tr>";
calendar_str += "<th>" + myMonth[0][0] + "</th>";
calendar_str += "<th>" + myMonth[0][1] + "</th>";
calendar_str += "<th>" + myMonth[0][2] + "</th>";
calendar_str += "<th>" + myMonth[0][3] + "</th>";
calendar_str += "<th>" + myMonth[0][4] + "</th>";
calendar_str += "<th>" + myMonth[0][5] + "</th>";
calendar_str += "<th>" + myMonth[0][6] + "</th>";
calendar_str += "</tr>";
calendar_str +='<tr><td colspan="7" class="caption">'+ iYear+' 骞� '+ iMonth+' 鏈�</td></tr>';
for (w = 1; w <= 6; w++) {
calendar_str += w == 6 ? "<tr class=\"date_end\">" : "<tr>";
for (d = 0; d < 7; d++) {
calendar_str +='<td ';
if(colorBg[w][d])
calendar_str +=colorBg[w][d];
calendar_str +='>';
if(myMonth[w][d])
calendar_str += myMonth[w][d];
else calendar_str +=" ";
calendar_str +="</td>";
}
calendar_str +="</tr>";
}
calendar_str +="</table>";
$("#"+element).html(calendar_str);
}
function getP(idate,average) {
var P= new Array();
P['s'] = DateAdd((idate.getMonth()+1)+'/'+idate.getDate()+'/'+idate.getFullYear(),average-17);
P['e'] = DateAdd((idate.getMonth()+1)+'/'+idate.getDate()+'/'+idate.getFullYear(),average-12);
return P;
}
function getLastP(idate,average) {
var PreDay = new Array();
PreDay =getLastY(idate,average);
return getP(PreDay['s'],average);
}
function getThisP(idate,average) {
return getP(idate,average);
}
function getNextP(idate,average) {
var PreDay = new Array();
PreDay =getNextY(idate,average);
return getP(PreDay['s'],average);
}
function getLastY(idate,average) {
var PreDay = new Array();
PreDay['s'] = DateAdd((idate.getMonth()+1)+'/'+idate.getDate()+'/'+idate.getFullYear(),0-average);
PreDay['e'] = DateAdd((idate.getMonth()+1)+'/'+idate.getDate()+'/'+idate.getFullYear(),0-average+ydate);
return PreDay;
}
function getThisY(idate,average) {
var PreDay = new Array();
PreDay['s'] = idate;
PreDay['e'] = DateAdd((idate.getMonth()+1)+'/'+idate.getDate()+'/'+idate.getFullYear(),ydate);
return PreDay;
}
function getNextY(idate,average) {
var PreDay = new Array();
PreDay['s'] = DateAdd((idate.getMonth()+1)+'/'+idate.getDate()+'/'+idate.getFullYear(),average);
PreDay['e'] = DateAdd((idate.getMonth()+1)+'/'+idate.getDate()+'/'+idate.getFullYear(),average+ydate);
return PreDay;
}
function ReculerP(iYear,iMonth,iDay,average) {
tmp = new Date(iYear,iMonth-1,iDay);
LastP = getLastP(tmp,average);
ThisP = getThisP(tmp,average);
NextP = getNextP(tmp,average);
LastY = getLastY(tmp,average);
ThisY = getThisY(tmp,average);
NextY = getNextY(tmp,average);
myMonth = fBuildCal(iYear,iMonth,LastP,ThisP,NextP,LastY,ThisY,NextY);
fDrawCal(iYear, iMonth,myMonth,'calendar1');
if(iMonth+1 >12){ iMonth = 1; iYear+=1;}
else iMonth += 1;
tmp = NextY['s'];
if((tmp.getMonth+1)<iMonth)tmp = getNextY(tmp,average)['s'];
LastP = getLastP(tmp,average);
ThisP = getThisP(tmp,average);
NextP = getNextP(tmp,average);
LastY = getLastY(tmp,average);
ThisY = getThisY(tmp,average);
NextY = getNextY(tmp,average);
myMonth = fBuildCal(iYear,iMonth,LastP,ThisP,NextP,LastY,ThisY,NextY);
fDrawCal(iYear, iMonth,myMonth,'calendar2');
}
function DateAdd(time,Number) {
return new Date(Date.parse(time) + (86400000 * Number));
}
function chkDate(sDate) {
var r=/\d{4}(?:-\d{1,2}){0,2}/
//姝e垯琛ㄨ揪寮忥紝鍒ゆ柇鏄惁涓簓yyy-mm-dd,yyyy-mm,yyyy鏍煎紡
if(sDate.match(r)==sDate){
var arr=sDate.split("-")
switch(arr.length){
//鏍规嵁涓嶅悓鐨剏yyy-mm-dd,yyyy-mm鏍煎紡鍒ゆ柇骞存湀鏃ユ暟瀛楁槸鍚︽纭�
case 3:
arr[1] = arr[1]-1;
var tmpDate=new Date(arr[0],arr[1],arr[2]);
if(tmpDate.getMonth()==arr[1] && tmpDate.getFullYear()==arr[0]) return true;
break;
case 2:
if(arr[1]<13) return true;
break;
default:
return false;
}
}
return false;
}
function DrawCalendar() {
$('#calendar1').html();
$('#calendar2').html();
year = $("#wyear").val();
month = $("#wmonth").val();
day = $("#wday").val();
time = year+'-'+month+'-'+day;
if(!chkDate(time)){
alert("鏃ユ湡鏍煎紡杈撳叆鏈夎锛岃杩斿洖妫€鏌�");
$('#wyear').focus();
return false;
}
iYear = parseInt(time.split("-")[0]);
//ydate = parseInt(document.getElementById("ydate").value)-1;
ydate = 4;
iMonth = parseInt(time.split("-")[1]);
iDay = parseInt(time.split("-")[2]);
if(!iYear || !iMonth || !iDay) {
alert("鏃ユ湡鏍煎紡杈撳叆鏈夎锛岃杩斿洖妫€鏌�");
$('#wyear').focus();
return false;
}
average = $("#wperiod").val();
ReculerP(iYear,iMonth,iDay,average);
document.getElementById('wresult').style.display = '';
var c1 = document.getElementById('calendar1').innerHTML;
var c2 = document.getElementById('calendar2').innerHTML;
var c = '<table cellspacing="0" cellpadding="0" border="0"><tr><td valign="top">娴嬭瘯缁撴灉锛�</td><td>'+c1+'</td><td width="10"> </td><td>'+c2+'</td></tr></table>';
var i = '';
return {c:c, i:i};
}
function wInit() {
document.getElementById('wresult').style.display = 'none';
var d = new Date();
d.setMonth(d.getMonth() - 1);
document.getElementById('wyear').value = d.getFullYear();
document.getElementById('wmonth').value = d.getMonth() + 1;
document.getElementById('wday').value = d.getDate();
document.getElementById('wyear').onclick = function(event) {WdatePicker({dateFmt:'yyyy',minDate:'1901', maxDate:'2050'})};
document.getElementById('wmonth').onclick = function(event) {WdatePicker({dateFmt:'M'})};
document.getElementById('wday').onclick = function(event) {WdatePicker({dateFmt:'d'})};
var p = document.getElementById('wperiod');
for (var i = 20; i <= 45; i++) {
p.options.add(new Option(i + '澶�', i));
}
p.options[8].selected = true;
}
function handleWork(obj) {
var v = obj.value;
obj.disabled = true;
// global callback
handleBegin();
var res = DrawCalendar();
if (typeof res == 'object' && res != null) {
// global callback
handleFinish(res.c, res.i);
}
obj.value = v;
obj.disabled = false;
}
js代码如下:
<!--
function CalConv(M)
{
FIRSTYEAR = 1936;
LASTYEAR = 2031;
LunarCal = [
new tagLunarCal(23, 3, 2, 17, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0 ), /* 1936 */
new tagLunarCal( 41, 0, 4, 23, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1 ),
new tagLunarCal( 30, 7, 5, 28, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1 ),
new tagLunarCal( 49, 0, 6, 33, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1 ),
new tagLunarCal( 38, 0, 0, 38, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1 ), /* 1940 */
new tagLunarCal( 26, 6, 2, 44, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0 ),
new tagLunarCal( 45, 0, 3, 49, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 ),
new tagLunarCal( 35, 0, 4, 54, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1 ),
new tagLunarCal( 24, 4, 5, 59, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1 ), /* 1944 */
new tagLunarCal( 43, 0, 0, 5, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1 ),
new tagLunarCal( 32, 0, 1, 10, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1 ),
new tagLunarCal( 21, 2, 2, 15, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1 ),
new tagLunarCal( 40, 0, 3, 20, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1 ), /* 1948 */
new tagLunarCal( 28, 7, 5, 26, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1 ),
new tagLunarCal( 47, 0, 6, 31, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1 ),
new tagLunarCal( 36, 0, 0, 36, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 ),
new tagLunarCal( 26, 5, 1, 41, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1 ), /* 1952 */
new tagLunarCal( 44, 0, 3, 47, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1 ),
new tagLunarCal( 33, 0, 4, 52, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0 ),
new tagLunarCal( 23, 3, 5, 57, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1 ),
new tagLunarCal( 42, 0, 6, 2, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1 ), /* 1956 */
new tagLunarCal( 30, 8, 1, 8, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0 ),
new tagLunarCal( 48, 0, 2, 13, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0 ),
new tagLunarCal( 38, 0, 3, 18, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 ),
new tagLunarCal( 27, 6, 4, 23, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0 ), /* 1960 */
new tagLunarCal( 45, 0, 6, 29, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0 ),
new tagLunarCal( 35, 0, 0, 34, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1 ),
new tagLunarCal( 24, 4, 1, 39, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0 ),
new tagLunarCal( 43, 0, 2, 44, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0 ), /* 1964 */
new tagLunarCal( 32, 0, 4, 50, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1 ),
new tagLunarCal( 20, 3, 5, 55, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0 ),
new tagLunarCal( 39, 0, 6, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0 ),
new tagLunarCal( 29, 7, 0, 5, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1 ), /* 1968 */
new tagLunarCal( 47, 0, 2, 11, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1 ),
new tagLunarCal( 36, 0, 3, 16, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0 ),
new tagLunarCal( 26, 5, 4, 21, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1 ),
new tagLunarCal( 45, 0, 5, 26, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1 ), /* 1972 */
new tagLunarCal( 33, 0, 0, 32, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1 ),
new tagLunarCal( 22, 4, 1, 37, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1 ),
new tagLunarCal( 41, 0, 2, 42, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1 ),
new tagLunarCal( 30, 8, 3, 47, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1 ), /* 1976 */
new tagLunarCal( 48, 0, 5, 53, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1 ),
new tagLunarCal( 37, 0, 6, 58, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1 ),
new tagLunarCal( 27, 6, 0, 3, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0 ),
new tagLunarCal( 46, 0, 1, 8, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0 ), /* 1980 */
new tagLunarCal( 35, 0, 3, 14, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1 ),
new tagLunarCal( 24, 4, 4, 19, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1 ),
new tagLunarCal( 43, 0, 5, 24, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1 ),
new tagLunarCal( 32, 10, 6, 29, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1 ), /* 1984 */
new tagLunarCal( 50, 0, 1, 35, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0 ),
new tagLunarCal( 39, 0, 2, 40, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1 ),
new tagLunarCal( 28, 6, 3, 45, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0 ),
new tagLunarCal( 47, 0, 4, 50, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1 ), /* 1988 */
new tagLunarCal( 36, 0, 6, 56, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0 ),
new tagLunarCal( 26, 5, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1 ),
new tagLunarCal( 45, 0, 1, 6, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0 ),
new tagLunarCal( 34, 0, 2, 11, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0 ), /* 1992 */
new tagLunarCal( 22, 3, 4, 17, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0 ),
new tagLunarCal( 40, 0, 5, 22, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0 ),
new tagLunarCal( 30, 8, 6, 27, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1 ),
new tagLunarCal( 49, 0, 0, 32, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1 ), /* 1996 */
new tagLunarCal( 37, 0, 2, 38, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1 ),
new tagLunarCal( 27, 5, 3, 43, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1 ),
new tagLunarCal( 46, 0, 4, 48, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1 ), /* 1999 */
new tagLunarCal( 35, 0, 5, 53, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1 ), /* 2000 */
new tagLunarCal( 23, 4, 0, 59, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1 ),
new tagLunarCal( 42, 0, 1, 4, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1 ),
new tagLunarCal( 31, 0, 2, 9, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0 ),
new tagLunarCal( 21, 2, 3, 14, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1 ), /* 2004 */
new tagLunarCal( 39, 0, 5, 20, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1 ),
new tagLunarCal( 28, 7, 6, 25, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1 ),
new tagLunarCal( 48, 0, 0, 30, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1 ),
new tagLunarCal( 37, 0, 1, 35, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1 ), /* 2008 */
new tagLunarCal( 25, 5, 3, 41, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1 ),
new tagLunarCal( 44, 0, 4, 46, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1 ),
new tagLunarCal( 33, 0, 5, 51, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1 ),
new tagLunarCal( 22, 4, 6, 56, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 ), /* 2012 */
new tagLunarCal( 40, 0, 1, 2, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 ),
new tagLunarCal( 30, 9, 2, 7, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1 ),
new tagLunarCal( 49, 0, 3, 12, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1 ),
new tagLunarCal( 38, 0, 4, 17, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0 ), /* 2016 */
new tagLunarCal( 27, 6, 6, 23, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1 ),
new tagLunarCal( 46, 0, 0, 28, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0 ),
new tagLunarCal( 35, 0, 1, 33, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0 ),
new tagLunarCal( 24, 4, 2, 38, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1 ), /* 2020 */
new tagLunarCal( 42, 0, 4, 44, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 ),
new tagLunarCal( 31, 0, 5, 49, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0 ),
new tagLunarCal( 21, 2, 6, 54, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1 ),
new tagLunarCal( 40, 0, 0, 59, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1 ), /* 2024 */
new tagLunarCal( 28, 6, 2, 5, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0 ),
new tagLunarCal( 47, 0, 3, 10, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1 ),
new tagLunarCal( 36, 0, 4, 15, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1 ),
new tagLunarCal( 25, 5, 5, 20, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0 ), /* 2028 */
new tagLunarCal( 43, 0, 0, 26, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1 ),
new tagLunarCal( 32, 0, 1, 31, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0 ),
new tagLunarCal( 22, 3, 2, 36, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0 ) ];
SolarCal = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];
SolarDays = [
0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365, 396,
0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366, 397 ];
AnimalIdx = ["棣� ", "缇� ", "鐚� ", "闆� ", "鐙� ", "璞� ", "榧� ", "鐗� ", "铏� ", "鍏� ", "榫� ", "铔� " ];
LocationIdx = [ "鍗�", "鏉�", "鍖�", "瑗�" ];
if (M==0) { //闃冲巻鍒伴槾鍘�
if (!IsInteger(form_jisuan.yyear.value) || !IsInteger(form_jisuan.ymonth.value) || !IsInteger(form_jisuan.yday.value)) return alert("璇疯緭鍏ュ悎娉曢槼鍘嗗勾鏈堟棩鏁板€�");
SolarYear = parseInt(form_jisuan.yyear.value);
SolarMonth = parseInt(form_jisuan.ymonth.value);
SolarDate = parseInt(form_jisuan.yday.value);
if ( SolarYear <= FIRSTYEAR || SolarYear > LASTYEAR ) return alert("璇疯緭鍏�1936-2031鏈夋晥骞翠唤");
sm = SolarMonth - 1;
if ( sm < 0 || sm > 11 ) return alert(璇疯緭鍏ユ湁鏁堟湀浠�);
leap = GetLeap( SolarYear );
if ( sm == 1 )
d = leap + 28;
else
d = SolarCal[sm];
if ( SolarDate < 1 || SolarDate > d ) return 3;
y = SolarYear - FIRSTYEAR;
acc = SolarDays[ leap*14 + sm ] + SolarDate;
kc = acc + LunarCal[y].BaseKanChih;
Kan = kc % 10;
Chih = kc % 12;
Location = LocationIdx[kc % 4];
Age = kc % 60;
if ( Age < 22 )
Age = 22 - Age;
else
Age = 82 - Age;
Age =Age + 3;
if (Age < 10)
Age=Age+60;
Animal = AnimalIdx[ Chih ];
if ( acc <= LunarCal[y].BaseDays ) {
y--;
LunarYear = SolarYear - 1;
leap = GetLeap( LunarYear );
sm += 12;
acc = SolarDays[leap*14 + sm] + SolarDate;
}
else
LunarYear = SolarYear;
l1 = LunarCal[y].BaseDays;
for ( i=0; i<13; i++ ) {
l2 = l1 + LunarCal[y].MonthDays[i] + 29;
if ( acc <= l2 ) break;
l1 = l2;
}
LunarMonth = i + 1;
LunarDate = acc - l1;
im = LunarCal[y].Intercalation;
if ( im != 0 && LunarMonth > im ) {
LunarMonth--;
if ( LunarMonth == im ) LunarMonth = -im;
}
if ( LunarMonth > 12 ) LunarMonth -= 12;
//alert("鍐滃巻/闃村巻鏃ユ湡涓猴細"+ LunarYear + "骞�" + LunarMonth + "鏈� " + LunarDate + "鏃� " );
var showgn = 0;
showgn = "鍐滃巻鏃ユ湡涓猴細"+ LunarYear + "骞�" + LunarMonth + "鏈� " + LunarDate + "鏃� ";
document.form_jisuan.g2n.value=showgn;
//form_jisuan.yyear.value = "";
//form_jisuan.ymonth.value = "";
//form_jisuan.yday.value = "";
return 0;
}
else /* 闃村巻杞槼鍘� */
{
if (!IsInteger(form_jisuan.nyear.value) || !IsInteger(form_jisuan.nmonth.value) || !IsInteger(form_jisuan.nday.value)) return alert("璇疯緭鍏ュ悎娉曞啘鍘嗗勾鏈堟棩鏁板€�");
LunarYear = parseInt(form_jisuan.nyear.value);
LunarMonth = parseInt(form_jisuan.nmonth.value);
LunarDate = parseInt(form_jisuan.nday.value);
if ( LunarYear < FIRSTYEAR || LunarYear >= LASTYEAR ) return alert("璇疯緭鍏�1936-2031鏈夋晥骞翠唤");
y = LunarYear - FIRSTYEAR ;
im = LunarCal[y].Intercalation;
lm = LunarMonth;
if ( lm < 0 )
{
if ( lm != -im )
return alert(璇疯緭鍏ユ湁鏁堟湀浠�);
}
else if ( lm < 1 || lm > 12 ) return alert(璇疯緭鍏ユ湁鏁堟湀浠�);
if ( im != 0 )
{
if ( lm > im )
lm++;
else if ( lm == -im )
lm = im + 1;
}
lm--;
if ( LunarDate > LunarCal[y].MonthDays[lm] + 29 )
return alert("鍐滃巻鏃ユ湡涓嶆纭�");
acc = 0;
for ( i=0; i < lm;i++) {
acc+= LunarCal[y].MonthDays[i] + 29;
}
acc +=LunarCal[y].BaseDays + LunarDate;
leap = GetLeap( LunarYear );
for ( i=13; i>=0; i-- ) {
if ( acc > SolarDays[leap*14+i] )
break;
}
SolarDate = acc - SolarDays[leap*14 + i] ;
if ( i <= 11 )
{
SolarYear = LunarYear;
SolarMonth = i + 1;
}
else
{
SolarYear = LunarYear + 1;
SolarMonth = i - 11;
}
leap = GetLeap( SolarYear );
y = SolarYear - FIRSTYEAR;
//acc = SolarDays[leap][SolarMonth-1] + SolarDate;
acc = SolarDays[leap*14 + SolarMonth-1] + SolarDate;
weekday = ( acc + LunarCal[y].BaseWeekday ) % 7;
kc = acc + LunarCal[y].BaseKanChih;
kan = kc % 10;
chih = kc % 12;
//alert("鍏巻/闃冲巻鏃ユ湡涓猴細"+ SolarYear + "骞�" + SolarMonth + "鏈�" + SolarDate + "鏃� " );
var showng = 0;
showng = "鍏巻鏃ユ湡涓猴細"+ SolarYear + "骞�" + SolarMonth + "鏈�" + SolarDate + "鏃� ";
document.form_jisuan.n2g.value=showng;
//form_jisuan.nyear.value = "";
//form_jisuan.nmonth.value = "";
//form_jisuan.nday.value = "";
return 0;
}//else缁撴潫
}
/* 闂板勾, 杩斿洖 0 骞冲勾, 1 闂板勾 */
function GetLeap( year )
{
if ( year % 400 == 0 )
return 1;
else if ( year % 100 == 0 )
return 0;
else if ( year % 4 == 0 )
return 1;
else
return 0;
}
function tagLunarCal( d, i, w, k, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13) {
this.BaseDays = d;
this.Intercalation = i;
this.BaseWeekday = w;
this.BaseKanChih = k;
this.MonthDays = [ m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13 ]; /* 姝ゅ啘鍘嗗勾姣忔湀涔嬪ぇ灏�, 0==灏忔湀(29鏃�), 1==澶ф湀(30鏃�) */
}
//-->
<!--
function OpenWin( url ) {
return window.open( url, 'coop', 'width=320,height=350,toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=0,resizable=1' );
}
function IsInteger(string ,sign)
{
var integer;
if ((sign!=null) && (sign!='-') && (sign!='+'))
{
alert('IsInter(string,sign)鐨勫弬鏁板嚭閿欙細nsign涓簄ull鎴�"-"鎴�"+"');
return false;
}
integer = parseInt(string);
if (isNaN(integer))
{
return false;
}
else if (integer.toString().length==string.length)
{
if ((sign==null) || (sign=='-' && integer<0) || (sign=='+' && integer>0))
{
return true;
}
else
return false;
}
else
return false;
}
//-->
代码如下:
ss="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_@";function v10toX(n,m){m=String(m).replace(/ /gi,"");if(m=="")return"";if(parseInt(m)!=m){M("鐠囩柉绶崗銉︽殻閺佸府绱�");return""}var t="";var a=ss.substr(0,n);while(m!=0){var b=m%n;t=a.charAt(b)+t;m=(m-b)/n}return t}function vXto10(n,m){m=String(m).replace(/ /gi,"");if(m=="")return"";var a=ss.substr(0,n);if(eval("m.replace(/["+a+"]/gi,'')")!=""){M("璇疯緭鍏�"+n+"杩涘埗鏁帮紒");return""}var t=0,c=1;for(var x=m.length-1;x>-1;x--){t+=c*(a.indexOf(m.charAt(x)));c*=n}return t}function vXtoY(n,m,y){a=vXto10(n*1,m);if(a=="")return"";a=v10toX(y,a);return a}function M(str){alert(str)}function convert(hex_input,id_input,hex_output,id_output){var input_v=document.getElementById(id_input).value;var outputEle=document.getElementById(id_output);var hex_in_v=document.getElementById(hex_input).value;var hex_out_v=document.getElementById(hex_output).value;outputEle.value=vXtoY(hex_in_v,input_v,hex_out_v)}function convert_c(hex_input_v,id_input,hex_output_v,id_output){var input_v=document.getElementById(id_input).value;var outputEle=document.getElementById(id_output);outputEle.value=vXtoY(hex_input_v,input_v,hex_output_v)}
有兴趣的同学可以一起看看。