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
", 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
", local.tm_hour, local.tm_min, local.tm_sec);
		Sleep(1000);//单位ms
	}
	system("pause");
	return 0;
}
原文地址:https://www.cnblogs.com/Henry-ZHAO/p/12725213.html