复制代码 代码如下:
var lunardate = {
madd: new array(0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334),
hsstring: '甲乙丙丁戊己庚辛壬癸',
ebstring: '子丑寅卯辰巳午未申酉戌亥',
numstring: 一二三四五六七八九十,
monstring: 正二三四五六七八九十冬腊,
calendardata: new array(0xa4b, 0x5164b, 0x6a5, 0x6d4, 0x415b5, 0x2b6, 0x957, 0x2092f, 0x497, 0x60c96, 0xd4a, 0xea5, 0x50da9, 0x5ad, 0x2b6, 0x3126e, 0x92e, 0x7192d, 0xc95, 0xd4a, 0x61b4a, 0xb55, 0x56a, 0x4155b, 0x25d, 0x92d, 0x2192b, 0xa95, 0x71695, 0x6ca, 0xb55, 0x50ab5, 0x4da, 0xa5b, 0x30a57, 0x52b, 0x8152a, 0xe95, 0x6aa, 0x615aa, 0xab5, 0x4b6, 0x414ae, 0xa57, 0x526, 0x31d26, 0xd95, 0x70b55, 0x56a, 0x96d, 0x5095d, 0x4ad, 0xa4d, 0x41a4d, 0xd25, 0x81aa5, 0xb54, 0xb6a, 0x612da, 0x95b, 0x49b, 0x41497, 0xa4b, 0xa164b, 0x6a5, 0x6d4, 0x615b4, 0xab6, 0x957, 0x5092f, 0x497, 0x64b, 0x30d4a, 0xea5, 0x80d65, 0x5ac, 0xab6, 0x5126d, 0x92e, 0xc96, 0x41a95, 0xd4a, 0xda5, 0x20b55, 0x56a, 0x7155b, 0x25d, 0x92d, 0x5192b, 0xa95, 0xb4a, 0x416aa, 0xad5, 0x90ab5, 0x4ba, 0xa5b, 0x60a57, 0x52b, 0xa93, 0x40e95),
year: null,
month: null,
day: null,
thedate: null,
getbit: function(m, n){
return (m >> n) & 1;
},
e2c: function(){
this.thedate = (arguments.length != 3) ? new date(): new date(arguments[0], arguments[1], arguments[2]);
var total, m, n, k;
var isend = false;
var tmp = this.thedate.getfullyear();
total = (tmp - 1921) * 365 + math.floor((tmp - 1921) / 4) + this.madd[this.thedate.getmonth()] + this.thedate.getdate() - 38;
if (this.thedate.getyear() % 4 == 0 && this.thedate.getmonth() > 1) {
total++;
}
for (m = 0; ; m++) {
k = (this.calendardata[m] for (n = k; n >= 0; n--) {
if (total isend = true;
break;
}
total = total - 29 - this.getbit(this.calendardata[m], n);
}
if (isend)
break;
}
this.year = 1921 + m;
this.month = k - n + 1;
this.day = total;
if (k == 12) {
if (this.month == math.floor(this.calendardata[m] / 0x10000) + 1) {
this.month = 1 - this.month;
}
if (this.month > math.floor(this.calendardata[m] / 0x10000) + 1) {
this.month--;
}
}
},
getcdatestring: function(){
var tmp = ;
tmp += this.hsstring.charat((this.year - 4) % 10);
tmp += this.ebstring.charat((this.year - 4) % 12);
tmp += 年 ;
if (this.month tmp += (闰);
tmp += this.monstring.charat(-this.month - 1);
} else {
tmp += this.monstring.charat(this.month - 1);
}
tmp += 月;
tmp += (this.day if (this.day % 10 != 0 || this.day == 10) {
tmp += this.numstring.charat((this.day - 1) % 10);
}
return tmp;
},
getlunarday: function(solaryear, solarmonth, solarday) {
if (solaryear 2020) {
return ;
} else {
solarmonth = (parseint(solarmonth) > 0) ? (solarmonth - 1): 11;
this.e2c(solaryear, solarmonth, solarday);
return this.getcdatestring();
}
}
};
调用方法:
复制代码 代码如下:
lunardate.getlunarday(2013, 1, 24);