c++输入一个时间,和系统时间作比较

c++输入一个时间,和系统时间作比较


有只小跳蛙
浏览 1702回答 4
4回答

慕沐林林

#include <stdio.h>#include <time.h>int main(){unsigned int hour,minu;///////////////////////////////输入部分int key=0;printf("input a time:\t");do{key=scanf("%u:%u",&hour,&minu);if (hour>24 || minu>60){printf("input error!\n");fflush(stdin);printf("input a time:\t");key=0;}}while(key!=2);/////////////////////////////比较部分{time_t systime;struct tm * timeinfo;time(&systime);timeinfo = localtime( &systime );printf("your input is:%d:%d\n",hour,minu);printf("system time is:%d %d\n",timeinfo->tm_hour,timeinfo->tm_min);if (hour>timeinfo->tm_hour){printf("your inpur is bigger!\n");return 1;}if (hour==timeinfo->tm_hour){if (minu>timeinfo->tm_min){printf("your inpur is bigger!\n");return 1;}if (minu==timeinfo->tm_min){printf("euqual!!\n");return 1;}else{printf("system time is bigger!\n");return 1;}}printf("system time is bigger!\n");return 1;}}&nbsp;
打开App,查看更多内容
随时随地看视频慕课网APP