#include#include #include tm* getTime() { time_t now; time(&now); return localtime(&now); } int main() { double cost; time_t start, end; time(&start);//获取程序开始运行的系统运行时间 bool bExit = false; while (!bExit) { tm *pTime = getTime(); printf("当前系统时间== %s", asctime(pTime)); //输出当前系统时间 if (pTime->tm_hour == 16 && pTime->tm_min == 22) //如果是10:08 分 就执行任务 { printf("行动开始rn"); } else { printf("等待命令rn"); } Sleep(5000); // 暂停5秒 time(&end); cost = difftime(end, start);//计算开始和当前时间差 if ((end - start) % 5 == 0) { printf("过了五秒n"); } } return 0; }



