写了段代码
char *starttime1 = strstr(p,"StartTime");
starttime1 +=10;
char *starttime2 = strstr(starttime1,"StartTime");
starttime2 -=2;
char tmp2[50] = {0};
memcpy(tmp2,starttime1,starttime2-starttime1);
printf(" $$$$$$$$$ starttime is %s \n\n\n",tmp2);
int tmp22[6] = {0};
tmp22[0]=(tmp2[2]-48)*10+tmp2[3]-48;
tmp22[1]=(tmp2[4]-48)*10+tmp2[5]-48;//yue/
tmp22[2]=(tmp2[6]-48)*10+tmp2[7]-48;//ri
tmp22[3]=(tmp2[8]-48)*10+tmp2[9]-48;//shi
tmp22[4]=(tmp2[10]-48)*10+tmp2[11]-48;//fen
tmp22[5]=(tmp2[12]-48)*10+tmp2[13]-48;//miao
printf(" tmp22 %d %d %d %d %d %d \n",tmp22[0],tmp22[1],tmp22[2],tmp22[3],tmp22[4],tmp22[5]);//nian
unsigned int iUnixERA_start;
iUnixERA_start = get_cur_secs(tmp22);
最后想调用get_cur_secs()函数得到具体的秒数
unsigned int get_cur_secs(char* cursystime)
{
int begin = 1970;
int end = 2000+cursystime[0];
unsigned int seconds = 0;
for (; begin < end; begin++)
{
if (begin % 4 == 0)
seconds += 366 * 86400;
else
seconds += 365 * 86400;
}
int i = 1;
for (i = 1; i < cursystime[1]; i++)
{
switch(i)
{
case 1:
seconds += 31*86400;
break;
case 2:
if (end % 4 == 0)
seconds += 29*86400;
else
seconds += 28*86400;
break;
case 3:
seconds += 31*86400;
break;
case 4:
seconds += 30*86400;
break;
case 5:
seconds += 31*86400;
break;
case 6:
seconds += 30*86400;
break;
case 7:
seconds += 31*86400;
break;
case 8:
seconds += 31*86400;
break;
case 9:
seconds += 30*86400;
break;
case 10:
seconds += 31*86400;
break;
case 11:
seconds += 30*86400;
break;
default:
break;
}
}
seconds += (cursystime[2] - 1)*86400 + cursystime[3]*3600 + cursystime[4]*60+cursystime[5];
return seconds;
}
原因是 人家要的是char * 我传递的是int * 。后面的函数算6个字节。而我的Int 一个就是4个字节,只算了1个半