程序代码接上所述
private DateTime m_Date;
public DateTime Date
{
get{ return m_Date;}
set{ m_Date = value;}
}
public CNDate()
{
Date = DateTime.Today;
}
public CNDate(DateTime dt)
{
Date = dt.Date;
}
//计算指定日期的星座序号
public int GetConstellation()
{
int Y, M, D;
Y = m_Date.Year;
M = m_Date.Month;
D = m_Date.Day;
Y = M * 100 + D;
if (((Y >= 321) && (Y <= 419))) { return 0;}
else if ((Y >= 420) && (Y
<= 520)) { return 1;}
else if ((Y >= 521) && (Y
<= 620)) { return 2;}
else if ((Y >= 621) && (Y
<= 722)) { return 3;}
else if ((Y >= 723) && (Y
<= 822)) { return 4;}
else if ((Y >= 823) && (Y
<= 922)) { return 5;}
else if ((Y >= 923) && (Y
<= 1022)) { return 6;}
else if ((Y >= 1023) &&
(Y <= 1121)) { return 7;}
else if ((Y >= 1122) &&
(Y <= 1221)) { return 8;}
else if ((Y >= 1222) ||
(Y <= 119)) { return 9;}
else if ((Y >= 120) && (Y
<= 218)) { return 10;}
else if ((Y >= 219) && (Y
<= 320)) { return 11;}
else { return -1;};
}
//计算指定日期的星座名称
public string GetConstellationName()
{
int Constellation;
Constellation = GetConstellation();
if ((Constellation >= 0) && (Constellation <= 11))
{ return
ConstellationName[Constellation];}
else
{ return "";};
}
//计算公历当天对应的节气 0-23,-1表示不是节气
public int l_GetLunarHolDay()
{
byte Flag;
int Day, iYear, iMonth, iDay;
iYear = m_Date.Year;
if ((iYear < START_YEAR) || (iYear > END_YEAR))
{ return -1;};
iMonth = m_Date.Month;
iDay = m_Date.Day;
Flag =
gLunarHolDay[(iYear - START_YEAR) * 12 + iMonth - 1];
if (iDay < 15)
{
Day = 15 - ((Flag >> 4) & 0x0f);}
else
{Day = (Flag & 0x0f) + 15;};
if (iDay == Day)
{
if (iDay > 15)
{ return (iMonth - 1) * 2 + 1;}
else
{ return (iMonth - 1) * 2;}
}
else
{return -1;};
}
public string FormatMonth(ushort iMonth, bool bLunar)
{
string szText = "正二三四五六七八九十";
string strMonth;
if ((!bLunar) && (iMonth == 1))
{ return "一月";}
if (iMonth <= 10)
{
strMonth = "";
strMonth = strMonth +
szText.Substring(iMonth - 1, 1);
strMonth = strMonth +
"月";
return strMonth;
}
if (iMonth == 11)
{ strMonth = "十一";}
else
{ strMonth = "十二";}
return strMonth + "月";
}
public string FormatLunarDay(ushort iDay)
{
string szText1 = "初十廿三";
string szText2 = "一二三四五六七八九十";
string strDay;
if ((iDay != 20) && (iDay != 30))
{
strDay =
szText1.Substring((iDay - 1) / 10, 1);
strDay = strDay +
szText2.Substring((iDay - 1) % 10, 1);
}
else
{
strDay =
szText1.Substring((iDay / 10) * 2 + 1, 2);
strDay = strDay + "十";
}
return strDay;
}
public string GetLunarHolDay()
{
ushort iYear, iMonth, iDay;
int i;
TimeSpan ts;
iYear = (ushort)(m_Date.Year);
if ((iYear < START_YEAR) || (iYear > END_YEAR))
{ return "";};
i = l_GetLunarHolDay();
if ((i >= 0) && (i <=
23))
{ return LunarHolDayName[i];}
else
{
ts = m_Date - (new DateTime(START_YEAR, 1, 1));
l_CalcLunarDate(out iYear, out iMonth, out iDay, (uint)(ts.Days));
return FormatMonth(iMonth, true) + FormatLunarDay(iDay);
}
}
//返回阴历iLunarYear年的闰月月份,如没有返回0 1901年1月---2050年12月
public int GetLeapMonth(ushort iLunarYear)
{
byte Flag;
if ((iLunarYear < START_YEAR) || (iLunarYear > END_YEAR))
{ return 0;};
Flag =
gLunarMonth[(iLunarYear - START_YEAR) / 2];
if ((iLunarYear - START_YEAR) % 2 == 0)
{return Flag >> 4;}
else
{return Flag & 0x0F;}
}
//返回阴历iLunarYer年阴历iLunarMonth月的天数,如果iLunarMonth为闰月,
//高字为第二个iLunarMonth月的天数,否则高字为0 1901年1月---2050年12月
public uint LunarMonthDays(ushort iLunarYear, ushort iLunarMonth)
{
int Height, Low
int iBit;
if ((iLunarYear < START_YEAR) || (iLunarYear > END_YEAR))
{ return 30; }
Height = 0;
Low = 29;
标签:
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@evget.com