/*
作用:計算該日期是今年第幾天
閏年的判斷條件:
1、能被4整除,但不能被100整除
2、可以被400整除
*/
int CalculateCurDay(int y,int m,int d)
{
int nDays=0;
int Y[12]={31,0,31,30,31,30,31,31,30,31,30,31};
if( (y%400==0||(y%4==0&&y%100!=0)) )
Y[1]=29;
else
Y[1]=28;
for(int i=0;i<m-1;i++)
nDays+=Y[i];
nDays+=d;
return nDays;
}
//基姆拉爾森計算公式根據日期判斷星期幾(1-7)
int CalculateWeekDay(int y, int m,int d)
{
if(m==1||m==2){
m+=12;
y--;
}
int nWeek = (d+2*m+3*(m+1)/5+y+y/4-y/100+y/400)%7;
nWeek+=1;
return nWeek;
}
// 目前日期為目前年份周數
int GetWeekOrderOfDate(int y,int m,int d)
{
int nOtherDays = CalculateCurDay(y,m,d)-(8-CalculateWeekDay(y,1,1)); //第一周之外的時間
int nWeekNum;
if (nOtherDays > 0){
if ( nOtherDays % 7 == 0 )
nWeekNum = nOtherDays/7;
else
nWeekNum = nOtherDays/7 + 1;
return nWeekNum + 1;
}
else{
return 1;
}
}