BOOL IsLeapYear(unsigned int nYear)
{
if((nYear % 4 ==0 && nYear % 400 != 0) ||(nYear % 400 == 0))
{
return TRUE;
}
else
{
return FALSE;
}
}
unsigned int MonthOfDays(unsigned int nYear,unsigned int nMonth)
{
switch(nMonth)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
{
return 31;
}
case 4:
case 6:
case 9:
case 11:
{
return 30;
}
case 2:
{
if (IsLeapYear(nYear))
{
return 29;
}
else
{
return 28;
}
}
}
}
unsigned int DayOfWeeks(unsigned int nYear,unsigned int nMonth,unsigned int nDay)
{
unsigned int nCount = 0;
for (unsigned int i = 1;i < nMonth;i ++)
{
nCount += MonthOfDays(nYear,nMonth);
}
nCount += nDay;
float fVal = nYear - 1 + (float)(nYear - 1) / 4 + (float)(nYear - 1) / 100 +(float)(nYear - 1) / 400 - 40 + nCount;
return (int) fVal % 7;
}
【VC++】万年历算法代码。根据年月日求星期。。
最新推荐文章于 2025-05-31 20:30:57 发布