首页 > 杂谈生活->C语言时钟代码(C语言实现时钟代码)
#include
#include
int main()
{
struct tm *time_ptr;
time_t current_time;
int hour, minute, second;
while(1) {
/* 获取当前时间 */
current_time = time(NULL);
time_ptr = localtime(¤t_time);
/* 处理时间格式 */
hour = time_ptr->tm_hour;
minute = time_ptr->tm_min;
second = time_ptr->tm_sec;
/* 输出到屏幕上 */
printf(\"%02d:%02d:%02d\\r\", hour, minute, second);
fflush(stdout);
/* 延时1秒 */
sleep(1);
}
return 0;
}
```