字符串中存着年月日的信息,将这些数据解析出来,并利用公式计算对应星期:
p = time_str_temp;
i=0;while((p != NULL) && (*p != '\0') && (*p != '/'))
{
year[i++] = *p++;
}
p++; // '/'
i = 0;
memset(month, 0, sizeof(month));
while((p != NULL) && (*p != '\0') && (*p != '/'))
{
month[i++] = *p++;
}
p++; //'/'
i = 0;
memset(day, 0, sizeof(day));
while((p != NULL) && (*p != '\0'))
{
day[i++] = *p++;
}
timeyear = atoi(year);
timemonth = atoi(month);
timeday = atoi(day);
if((timemonth == 1) || (timemonth ==2))
{
timemonth = timemonth+12;
timeyear = timeyear-1;
}
if((timemonth<13 && timemonth>0) && (timeday<32 &&timeday>0))
{
time_week = (timeday+2*timemonth+3*(timemonth+1)/5+timeyear+timeyear/4-timeyear/100+timeyear/400)%7+1;
}