如何用C语言实现一个当前系统时间显示
我想在VS2012环境下写一个C程序,实时显示当前时间,请问怎么实现?
[解决办法]
这样应该可以的,你试试!
#include <stdio.h>
#include <time.h>
#include <windows.h>
void main()
{
time_t Curtime = (time_t)0;
struct tm* RetTime = NULL;
while (1)
{
time(&Curtime);
RetTime = localtime(&Curtime);
printf("\r%04d-%02d-%02d %02d:%02d:%02d"
,RetTime->tm_year + 1900
,RetTime->tm_mon + 1
,RetTime->tm_mday
,RetTime->tm_hour
,RetTime->tm_min
,RetTime->tm_sec);
Sleep(100);
}
}