通过日期计算某一天是这一年中的第几天
/*
val---要传入的日期字符串,如2017/8/4*/#include <time.h>#include <string.h>#include <stdio.h>const char SPLIT1[2]="-";
const char SPLIT2[2]="/";const char SPLIT3[2]=" ";int getDay(char *val)
{ char *inDate[3]; struct tm setInfo; time_t tmpInfo;//将年月日分割
int i=0; inDate[i]=strtok(val,SPLIT2); while(++i<3) { inDate[i]=strtok(NULL,SPLIT2); }setInfo.tm_year=atoi(inDate[0])-1900;
setInfo.tm_mon=atoi(inDate[1])-1; setInfo.tm_mday=atoi(inDate[2]); setInfo.tm_hour=0; setInfo.tm_min=0; setInfo.tm_sec=0; setInfo.tm_isdst=-1;tmpInfo=mktime(&setInfo);
printf("%d\n",setInfo.tm_yday+1);return 0;
}