function Date2Lunardate(ymd)
{
var days = Date2Days(ymd);
var monthdays = Days2Monthdays(days);
var keysolar = Monthdays2Keysolar(monthdys);
var spring = keysolar - (keysolar % 24);
spring <<= 4;
var springdays = Solardays2Days(spring);
var firstmonth = Days2Monthdays(springdays);
keysolar = Monthdays2Keysolar(firstmonth);
firstmonth >>>=5;
if((keysolar % 24) != 1)firstmonth++;
spring += 384;
var springdays = Solardays2Days(spring);
var lastmonth = Days2Monthdays(springdays);
keysolar = Monthdays2Keysolar(lastmonth);
lastmonth >>>=5;
if((keysolar % 24) == 1)lastmonth--;
var leap = 0 , vacancy = 0 , calendarmonth = 0 , months;
for(int i=firstmonth; i=lastmonth;i++)
{
months = i << 5;
keysolar = Monthdays2Keysolar(months);
switch((((keysolar + 1) % 24) >>> 1) - calendarmonth)
{
case 0 : {leap = (((keysolar + 1) % 24) >>> 1);break;}
case 2 : {vacancy = (((keysolar + 1) % 24) >>> 1)-1;calendarmonth = (((keysolar + 1) % 24) >>> 1);break;}
default : {calendarmonth = (((keysolar + 1) % 24) >>> 1);break;}
}}
keysolar = Monthdays2Keysolar(monthdys);
if(vacancy)
{
if(leap > vacancy)
{
if(((((keysolar + 1) % 24) >>> 1) > vacancy) && ((((keysolar + 1) % 24) >>> 1) < leap) calendarmonth = (((keysolar + 1) % 24) >>> 1) - 1;
else if(((((keysolar + 1) % 24) >>> 1) = leap) && ((((keysolar + 1) % 24) % 2) =1)) calendarmonth = (((keysolar + 1) % 24) >>> 1) - 1;
else calendarmonth = (((keysolar + 1) % 24) >>> 1);
}
else
{
if(((((keysolar + 1) % 24) >>> 1) > leap) && ((((keysolar + 1) % 24) >>> 1) < vacancy) calendarmonth = (((keysolar + 1) % 24) >>> 1) + 1;
else if(((((keysolar + 1) % 24) >>> 1) = leap) && ((((keysolar + 1) % 24) % 2) =1)) calendarmonth = (((keysolar + 1) % 24) >>> 1) + 1;
else calendarmonth = (((keysolar + 1) % 24) >>> 1);
}
}
else if(leap)
{
if(((((keysolar + 1) % 24) >>> 1) = leap) && ((((keysolar + 1) % 24) % 2) =1)) calendarmonth = (((keysolar + 1) % 24) >>> 1) + 100;
else calendarmonth = (((keysolar + 1) % 24) >>> 1);
}
else calendarmonth = (((keysolar + 1) % 24) >>> 1);
var year = (keysolar - 1- ((keysolar - 1) % 24) / 24;
return ((year * 100000) + (month * 100) + (monthdays & 0x1f) + 1); //lunar date format: yyyylmmdd;
}
function Monthdays2Keysolar()
{
var month1stday = monthdays & 0xffe0;
var firstday = Monthdays2Days(month1stday);
var solardays = Days2Solardays(firstdays-1);
var solar1 = solardays >>> 4;
month1stday += 0x20;
firstday = Monthdays2Days(month1stday);
solardays = Days2Solardays(firstdays);
var solar2 = solardays >>> 4;
switch(solar2-solar1)
{
case 1: {return solar2;break;}
case 3: {return solar2-1;break;}
default: {return ((solar2 % 2) = 1 ? solar2 : solar2-1);break;}
}
}
function Lunardate2Monthdays(ylmd)
{
var year = (ylmd - (ylmd % 100000)) / 100000 - 1924;
var spring = year * 24;
spring <<= 4;
var springdays = Solardays2Days(spring);
var firstmonth = Days2Monthdays(springdays);
var keysolar = Monthdays2Keysolar(firstmonth);
firstmonth >>>= 5;
if((keysolar % 24) != 1) firstmonth++;
spring += 384;
springdays = Solardays2Days(spring);
var lastmonth = Days2Monthdays(springdays)
keysolar = Monthdays2Keysolar(lastmonth);
lastmonth >>>= 5;
if((keysolar % 24) == 1) lastmonth--;
var leap = 0 , vacancy = 0 , calendarmonth = 0 , months;
for(int i=firstmonth; i=lastmonth;i++)
{
months = i << 5;
keysolar = Monthdays2Keysolar(months);
switch((((keysolar + 1) % 24) >>> 1) - calendarmonth)
{
case 0 : {leap = (((keysolar + 1) % 24) >>> 1);break;}
case 2 : {vacancy = (((keysolar + 1) % 24) >>> 1)-1;calendarmonth = (((keysolar + 1) % 24) >>> 1);break;}
default : {calendarmonth = (((keysolar + 1) % 24) >>> 1);break;}
}
}
var month = ((ylmd % 10000) - ((ylmd % 10000) % 100)) / 100 - 1;
var leapflag = ((ylmd % 100000) - ((ylmd % 100000) % 10000)) / 10000;
if(leap && (! vacancy )){
if(leapflag) month++;
else if(month > leap) month++;}
month += firstmonth;
return (month << 5) + (ylmd % 100);}
function Lunardate2Days(ylmd){
var monthdays = Lunardate2Monthdays(ylmd);
return Monthdays2Days(monthdays);}
function Date2Days(ymd)//公历日期转流水日
{
}
function Days2Date(days)//公历日期转流水日
{
}
function Days2Monthdays(days)//流水日转流水月日
{
}
function Monthdays2Days(monthdays)//流水月日转流水日
{
}
function Days2Solardays(days)//流水日转流水气日
{
}
function Solardays2Days(solardays)//流水气日转流水日
{
}
[此贴子已经被作者于2012-1-1 15:26:54编辑过]