标签:time split info ring char std string ++ get
获得某一天是这一年中的第几天
如:
./g 20117/2/1
32
#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);
int main(int argc,char *argv[])
{
getDay(argv[1]);
return 0;
}
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 (setInfo.tm_yday+1);
}
getDat(char *val)获得某一天是这一年中的第几天
标签:time split info ring char std string ++ get
原文地址:http://www.cnblogs.com/Mr-Wenyan/p/7532942.html