const char* pszEndTime =“2021-09-10 12:00:00 struct tm end = { 0 }; sscanf_s(pszEndTime,"%d-%d-%d %d:%d:%d", &end.tm_year, &end.tm_mon, &end.tm_mday , &end.tm_hour, &end.tm_min, &end.tm_sec); end.tm_year -= 1900; end.tm_mon -= 1; end.tm_isdst = 0; time_t tEnd = mktime(&end); time_t tNow; time(&tNow); //从1970至今多少秒 long fDis = difftime(tEnd, tNow); int nDay = fDis / (24 * 60 * 60); int nHour = fDis % (24 * 60 * 60) / (60 * 60); int nMin = fDis % (24 * 60 * 60) % (60 * 60) / 60; int nSec = fDis % 60; nSec = fDis % 60;