js获取阴历阳历时间

function getLunarCld() { var sDate = new Date(), aWeek = ['日', '一', '二', '三', '四', '五', '六'], sRet = (sDate.getYear() < 100 ? sDate.getYear() + 1900 : sDate.getYear()) + '年' + (sDate.getMonth() + 1) + '月' + sDate.getDate() + '日'; sRet += ' 星期' + aWeek[sDate.getDay()]; sRet += ' ' + (getCNDateStr(sDate)); return (sRet); } function getDaysNumberOfDate(gDate) { return parseInt((Date.parse(gDate) - Date.parse(gDate.getYear() + '/1/1')) / 86400000) + 1; } function getCnDateOfDate(gDate) { var aCnData = [0x16, 0x2a, 0xda, 0x00, 0x83, 0x49, 0xb6, 0x05, 0x0e, 0x64, 0xbb, 0x00, 0x19, 0xb2, 0x5b, 0x00, 0x87, 0x6a, 0x57, 0x04, 0x12, 0x75, 0x2b, 0x00, 0x1d, 0xb6, 0x95, 0x00, 0x8a, 0xad, 0x55, 0x02, 0x15, 0x55, 0xaa, 0x00, 0x82, 0x55, 0x6c, 0x07, 0x0d, 0xc9, 0x76, 0x00, 0x17, 0x64, 0xb7, 0x00, 0x86, 0xe4, 0xae, 0x05, 0x11, 0xea, 0x56, 0x00, 0x1b, 0x6d, 0x2a, 0x00, 0x88, 0x5a, 0xaa, 0x04, 0x14, 0xad, 0x55, 0x00, 0x81, 0xaa, 0xd5, 0x09, 0x0b, 0x52, 0xea, 0x00, 0x16, 0xa9, 0x6d, 0x00, 0x84, 0xa9, 0x5d, 0x06, 0x0f, 0xd4, 0xae, 0x00, 0x1a, 0xea, 0x4d, 0x00, 0x87, 0xba, 0x55, 0x04], aCnMonth = [], aCnMonthDays = [], sCnBeginDay, sLeapMonth, aByte = [], I, sCnMonthData, nDaysCount, nCnDaysCount, nResultMonth, nResultDay, sYear = gDate.getYear(), sMonth = gDate.getMonth() + 1, sDay = gDate.getDate(); if (sYear < 100) sYear += 1900; if ((sYear < 1997) || (sYear > 2020)) { return 0; } aByte[0] = aCnData[(sYear - 1997) * 4]; aByte[1] = aCnData[(sYear - 1997) * 4 + 1]; aByte[2] = aCnData[(sYear - 1997) * 4 + 2]; aByte[3] = aCnData[(sYear - 1997) * 4 + 3]; if ((aByte[0] & 0x80) != 0) { aCnMonth[0] = 12; } else { aCnMonth[0] = 11; } sCnBeginDay = (aByte[0] & 0x7f); sCnMonthData = aByte[1]; sCnMonthData = sCnMonthData << 8; sCnMonthData = sCnMonthData | aByte[2]; sLeapMonth = aByte[3]; for (I = 15; I >= 0; I--) { aCnMonthDays[15 - I] = 29; if (((1 << I) & sCnMonthData) != 0) { aCnMonthDays[15 - I]++; } if (aCnMonth[15 - I] == sLeapMonth) { aCnMonth[15 - I + 1] = -sLeapMonth; } else { if (aCnMonth[15 - I] < 0) { aCnMonth[15 - I + 1] = -aCnMonth[15 - I] + 1; } else { aCnMonth[15 - I + 1] = aCnMonth[15 - I] + 1; } if (aCnMonth[15 - I + 1] > 12) { aCnMonth[15 - I + 1] = 1; } } } nDaysCount = getDaysNumberOfDate(gDate) - 1; if (nDaysCount <= (aCnMonthDays[0] - sCnBeginDay)) { if ((sYear > 1901) && (getCnDateOfDate(new Date((sYear - 1) + '/12/31')) < 0)) { nResultMonth = -aCnMonth[0]; } else { nResultMonth = aCnMonth[0]; } nResultDay = sCnBeginDay + nDaysCount; } else { nCnDaysCount = aCnMonthDays[0] - sCnBeginDay; I = 1; while ((nCnDaysCount < nDaysCount) && (nCnDaysCount + aCnMonthDays[I] < nDaysCount)) { nCnDaysCount += aCnMonthDays[I]; I++; } nResultMonth = aCnMonth[I]; nResultDay = nDaysCount - nCnDaysCount; } if (nResultMonth > 0) { return nResultMonth * 100 + nResultDay; } else { return nResultMonth * 100 - nResultDay; } } function getCnYearOfDate(gDate) { var sYear = gDate.getYear(), MM = gDate.getMonth() + 1, CnMM = parseInt(Math.abs(getCnDateOfDate(gDate)) / 100); if (sYear < 100) sYear += 1900; if (CnMM > MM) sYear--; sYear -= 1864; return getCnEra(sYear) + '年'; } function getCnMonthofDate(gDate) { var aCnMonthStr = ['零', '正', '二', '三', '四', '五', '六', '七', '八', '九', '十', '冬', '腊'], sMonth = parseInt(getCnDateOfDate(gDate) / 100); if (sMonth < 0) { return '闰' + aCnMonthStr[-sMonth] + '月'; } else { return aCnMonthStr[sMonth] + '月'; } } function getCNDayOfDate(gDate) { var aCnDayStr = ['零', '初一', '初二', '初三', '初四', '初五', '初六', '初七', '初八', '初九', '初十', '十一', '十二', '十三', '十四', '十五', '十六', '十七', '十八', '十九', '二十', '廿一', '廿二', '廿三', '廿四', '廿五', '廿六', '廿七', '廿八', '廿九', '三十'], sDay = (Math.abs(getCnDateOfDate(gDate))) % 100; return aCnDayStr[sDay]; } function getDaysNumberOfMonth(gDate) { var MM1 = gDate.getYear(); MM1 < 100 ? MM1 += 1900 : MM1; var MM2 = MM1; MM1 += '/' + (gDate.getMonth() + 1); MM2 += '/' + (gDate.getMonth() + 2); MM1 += '/1'; MM2 += '/1'; return parseInt((Date.parse(MM2) - Date.parse(MM1)) / 8640000); } function getCnEra(sYear) { var aTG = ['甲', '乙', '丙', '丁', '戊', '己', '庚', '辛', '壬', '癸'], aDZ = ['子', '丑', '寅', '卯', '辰', '巳', '午', '未', '申', '酉', '戌', '亥']; return aTG[sYear % 10] + aDZ[sYear % 12]; } function getCNDateStr(gDate) { if (getCnMonthofDate(gDate) == '零月') { return ' 请调整您的计算机日期!'; } else { return getCnMonthofDate(gDate) + getCNDayOfDate(gDate); } }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值