C利用系统库显示本机当前时间
#include <stdio.h> //给printf用
#include <stdlib.h> //给system用
#include <time.h>
#include <windows.h> //Sleep函数在系统库中
/*
已知获取本机当前时间的函数如下:
time_t now
struct tm local;
time(&now);
localtime(&local,&now);
printf("%2d:%2d:%2d\r", local.tm_hour, local.tm_min, local.tm_sec);
*/
int main()
{
time_t now;
struct tm local;
while (1)
{
time(&now);
localtime_s(&local,&now);//localtime取now时间赋值给local
printf("%2d:%2d:%2d\r", local.tm_hour, local.tm_min, local.tm_sec);
Sleep(1000);//单位ms
}
system("pause");
return 0;
}