# 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;
}
*/

06-26 5038

12-11 3926

#### C语言时间处理函数与实例

2013年03月08日 16KB 下载

07-04 16

04-19 753

07-30 1.1万

09-22 172

09-03 1677

12-25 2370

01-14 2286