给定日期计算星期几

蔡勒(Zeller)公式,

传送门

int getDayofWeek(int day, int month, int year)
{
     int week;
     if(month < 3)
     {
        year -= 1;
        month += 12;
     }
     int c = int(year/100);
     int y = year - 100*c;
     week = int(c/4) - 2*c + y + int(y/4) + (26*(month + 1)/10) + day - 1;    // caculate the day of week
     week = (week%7 + 7) % 7;
     return week;   //0 for Sunday, 1 for Monday... 6 for Saturday
}
转载请注明来源:Leoncom-《给定日期计算星期几》
Trackback

no comment untill now

Add your comment now