#include #include #include #ifdef WIN32 #include #else #include #endif //win32 using namespace std; struct DATETIME { int year; int month; int date; int hour; int minute; int second; }; void sleepcp(int milliscends); int main(){ DATETIME dateTime; int isLeapYear = 0; cout << "input time with format(yyyy MM dd hh mm ss):"; cin >> dateTime.year >> dateTime.month >> dateTime.date >> dateTime.hour >> dateTime.minute >> dateTime.second; while(true){ #ifdef WIN32 system("cls"); #else system("clear"); #endif if(dateTime.year % 400 == 0 || (dateTime.year % 4 == 0 && dateTime.year % 100 != 0)){ isLeapYear = 1; } dateTime.second++; if(dateTime.second == 60){ dateTime.second = 1; dateTime.minute++; } if(dateTime.minute >= 60){ dateTime.minute = 0; dateTime.hour++; cout << "one hour. \7" << endl; } if(dateTime.hour >= 24){ dateTime.hour = 0; if((dateTime.month == 1 || dateTime.month == 3 || dateTime.month == 5 || dateTime.month == 7 || dateTime.month == 8 || dateTime.month == 10 || dateTime.month == 12) && dateTime.date == 31){ dateTime.date = 1; dateTime.month++; } else if((dateTime.month == 4 || dateTime.month == 6 || dateTime.month == 9 || dateTime.month == 11) && dateTime.date == 30){ dateTime.date = 1; dateTime.month++; } else if(dateTime.month == 2 && ((dateTime.date == 28 && isLeapYear == 0) || (dateTime.date == 29 && isLeapYear == 1))){ dateTime.date = 1; dateTime.month++; }else{ dateTime.date++; } } if(dateTime.month >= 12){ dateTime.month = 1; dateTime.year++; } cout << '\a'; cout << "DateTime: " << dateTime.year << "-" << dateTime.month << "-" << dateTime.date << " "; cout << dateTime.hour << ":" << dateTime.minute << ":" << dateTime.second << endl; cout << "Leap Year: " << (isLeapYear == 0 ? "No" : "Yes") << endl; sleepcp(1000); } return 0; } void sleepcp(int milliseconds){ #ifdef WIN32 Sleep(milliseconds); #else usleep(milliseconds * 1000); #endif }