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

135人阅读 评论(0)

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

0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：17252次
• 积分：391
• 等级：
• 排名：千里之外
• 原创：23篇
• 转载：11篇
• 译文：0篇
• 评论：2条
文章分类
阅读排行
评论排行
最新评论