int getSecsFromCurrent(const char* endtimestr)
{
time_t timepend ,timepnow ;
struct tm tmend ;
struct tm * tmnow ;
char strtoday[11]={0},strnow[9]={0},strCurrentdayEndTime[28]={0} ;
int iTotalSecNum = 0 ;
time(&timepnow);
tmnow = localtime(&timepnow) ;
sprintf(strtoday,"%04d-%02d-%02d",
tmnow->tm_year + 1900,tmnow->tm_mon+1,tmnow->tm_mday);
sprintf(strnow,"%02d:%02d:%02d",
tmnow->tm_hour,tmnow->tm_min,tmnow->tm_sec);
//strcpy(strCurrentdayEndTime,strtoday) ;
//strcat(strCurrentdayEndTime," 14:50:00") ;
sprintf(strCurrentdayEndTime,"%s %s",strtoday,endtimestr) ;
memset(&tmend, 0, sizeof(struct tm));
strptime(strCurrentdayEndTime,"%Y-%m-%d %H:%M:%S", &tmend);
timepend = mktime(&tmend);
iTotalSecNum =(int)difftime(timepend,timepnow);
return iTotalSecNum ;
}
int main(int argc, char *argv[])
{
for(int idx=0;idx<10;idx++){
printf("(%d)\n",getSecsFromCurrent("12:12:13") ) ;
sleep(1) ;
} //for
}
留言列表