C语言或其开机时间与控制台电子时钟

C语言或其开机时间与控制台电子时钟_第1张图片

 

printf("已经开机:%d分钟/n",GetTickCount()/1000/60);

一句代码而已,呵呵。

 

time_t m_time; time(&m_time); tm* tm_local=localtime(&m_time); while(1) { clrscr(); printf("已经开机:%d分钟/n",GetTickCount()/1000/60); time_t m_time; time(&m_time); tm* tm_local=localtime(&m_time); gotoxy(0,2); printf("%d:%d:%d %d:%d:%02d/n",tm_local->tm_year+1900,tm_local->tm_mon+1,tm_local->tm_mday,tm_local->tm_hour,tm_local->tm_min,tm_local->tm_sec); Sleep(200); } getchar();

 

#include <Windows.h> #include <time.h> void gotoxy(int x,int y) { CONSOLE_SCREEN_BUFFER_INFO csbiInfo; HANDLE hConsoleOut; hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE); GetConsoleScreenBufferInfo(hConsoleOut,&csbiInfo); csbiInfo.dwCursorPosition.X = x; csbiInfo.dwCursorPosition.Y = y; SetConsoleCursorPosition(hConsoleOut,csbiInfo.dwCursorPosition); } void clrscr(void) { CONSOLE_SCREEN_BUFFER_INFO csbiInfo; HANDLE hConsoleOut; COORD Home = {0,0}; DWORD dummy; hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE); GetConsoleScreenBufferInfo(hConsoleOut,&csbiInfo); FillConsoleOutputCharacter(hConsoleOut,' ',csbiInfo.dwSize.X * csbiInfo.dwSize.Y,Home,&dummy); csbiInfo.dwCursorPosition.X = 0; csbiInfo.dwCursorPosition.Y = 0; SetConsoleCursorPosition(hConsoleOut,csbiInfo.dwCursorPosition); }

你可能感兴趣的:(c,buffer,语言,output)