C语言显示当前时间
#include<stdio.h> #include<Windows.h> #include<time.h> struct clock { int hour; int minute; int second; }; typedef struct clock CLOCK; int main() { CLOCK t = { 0,0,0 }; int n = 100, i = 0; char c; time_t now; struct tm local; while (1) { time(&now); localtime_s(&local, &now); printf("%2d:%2d:%2d\r", local.tm_hour, local.tm_min, local.tm_sec); } /* while (i++<n) { t.second++; if (t.second >= 60) { t.second = 0; t.minute++; } if (t.minute >= 60) { t.minute = 0; t.hour++; } if (t.hour >= 24) t.hour = 0; printf("%2d:%2d:%2d\r", t.hour, t.minute, t.second); Sleep(1000); } */ }