# c语言关于时间的两个函数

#include<stdio.h>

int datetoweek(int yr, int mn,int day)
{
int i;
int days=0;
int s;
int week;
int mont[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};

if((0==yr%4 && 0!=yr%100)||0==yr%400)
mont[2]=29;
else
mont[2]=28;
for (i=0;i<mn;i++)
days+=mont[i];
days+=day;
s=yr-1+(int)((yr-1)/4)-(int)((yr-1)/100)+(int)((yr-1)/400)+days;
week=s%7;

return week;
}

int main()
{
int week1,week2,week3;

week1 = datetoweek(2015,11,17);
week2 = datetoweek(2015,10,17);
week3 = datetoweek(2015,12,17);

printf("week1=%d,week2=%d,week3=%d \r\n",week1,week2,week3);

return 0;
}

/*
int8 GetMonthFromDays(uint32 days,uint32 year, uint32 *returnDays)
{
int i =0;
uint32 totalday = 0;
for(i =0; i < 12 ; i++) {
if(days < totalday) {
break;
}
if(((year&0x3) == 0)&&(i == 1))
totalday += 29;
else
totalday += norm_month_table[i];
}
if(((year&0x3) == 0)&&(i == 2))
*returnDays = days - totalday + 29 + 1;
else
*returnDays = days - totalday + norm_month_table[i - 1] + 1;
return i;
}
*/

• 本文已收录于以下专栏：

举报原因： 您举报文章：c语言关于时间的两个函数 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)