c语言 数字时钟程序 要求显示格式为:HH:MM:SS

2025-03-07 02:11:17
推荐回答(1个)
回答1:

#include
#include
#include
#define BUF_SIZE 80
int main()
{
time_t t;
struct tm *tm;
char s[BUF_SIZE];
if(time(&t) == ((time_t)-1)) return 1;
tm = localtime(&t);
if(!tm) return 1;
strftime(s, sizeof(s), ":%H:%M:%S", tm);
printf("%s\n", s);
system("pause");
return 0;
}