linux下怎样用c语言编写一个时钟
2个回答
展开全部
我希望你只是需要如何知道时间,而不是写你一个时钟程序,那个太复杂了,如果只是想如何知道时间-
#include <stdio.h>
#include <time.h>
int main(void)
{
struct tm *tm_ptr;
time_t the_time;
(void)time(&the_time);
tm_ptr=localtime(&the_time);
printf("Date: %04d/%02d/%02d\n",
1900+tm_ptr->tm_year,tm_ptr->tm_mon+1,tm_ptr->tm_mday);
printf("Time: %02d:%02d:%02d\n",
tm_ptr->tm_hour,tm_ptr->tm_min,tm_ptr->tm_sec);
return(0);
}
#include <stdio.h>
#include <time.h>
int main(void)
{
struct tm *tm_ptr;
time_t the_time;
(void)time(&the_time);
tm_ptr=localtime(&the_time);
printf("Date: %04d/%02d/%02d\n",
1900+tm_ptr->tm_year,tm_ptr->tm_mon+1,tm_ptr->tm_mday);
printf("Time: %02d:%02d:%02d\n",
tm_ptr->tm_hour,tm_ptr->tm_min,tm_ptr->tm_sec);
return(0);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询