/*
* This only works for the Gregorian calendar - i.e. after 1752 (in the UK)
*/
/*计算公历*/
void GregorianDay(struct rtc_time * tm)
{
int lastyear;
int leapstodate;
int day;
int MonthOffset[]={0,31,59,90,120,151,181,212,243,273,304,334};
lastyear = tm->tm_year - 1;
//计算从公历元年到计数的前一年共经历多少个闰年
leapstodate = lastyear/4 - lastyear/100 + lastyear/400;
/*如若计数的这一年为闰年,且计数的月份在2月之后,则日数加1,否则不加1*/
if((tm->tm_year%4 == 0) && (tm->tm_year%100 == 0)||(tm->tm_year%400 == 0)&& (tm->tm_month > 2))
{
day = 1;
}
else
{
day = 0;
}
/*计算从公元元年元旦到计数日期一共有多少天*/
day += lastyear*365 + leaptodate + MonthOffset[tm->tm_month - 1] + tm->tm_mday;
tm->tm_wday = day%7;
}
不懂红色标注的部分有什么作用,没看懂怎么回事?大神指教 |