c语言编时钟

 我来答 举报
bldx123
推荐于2017-09-23 · 超过31用户采纳过TA的回答
知道答主
回答量:60
采纳率:0%
帮助的人:0
展开全部
这个行吗?

#include "stdio.h"
#include "time.h"
#include "dos.h"
#include "windows.h"
#include "string.h"
#include "ctype.h"

int year_r(); //显示年
int month_h(); //月
int date_e(); //日
int time_e(); //时间
char * time_ta(); //将日期时间转换成字符串
int wait_t(); //延时1秒

char * time_ta() //将日期时间转换成字符串
{
char *q;
time_t t;
t=time(NULL);
q=ctime(&t);
//printf("*q_address = 0x%x\n",q);
return (q);
}

int wait_t() //延时1秒
{
long temp_total=0;
time_t time_temp;
time_temp=time(NULL);
temp_total=time_temp;
for(;;)
{
time_temp=time(NULL);
if(abs(time_temp - temp_total) >=1)
break;
}

return (0);
}

int main()
{
int temp;

system("cls"); //清屏
printf("\n\n\n\n\n\n\n\n\t\t\t");
year_r();
printf("年");
temp = month_h();
if (temp != 13)
{
printf("%d",temp);
printf("月");
}
else printf("month error!\n");
date_e();
printf("日");
time_e();
printf("\r");
for(;;) //显示年月日时分秒
{
wait_t(); // 1秒钟到显示年月日时分秒
system("cls");
printf("\n\n\n\n\n\n\n\n\t\t\t");
year_r();
printf("年");
temp = month_h();
if (temp != 13)
{
printf("%d",temp);
printf("月");
}
else printf("month error!\n");

date_e();
printf("日");
time_e();
}
getchar();

}

int year_r() //显示年
{

char *p;
int i;
p=time_ta();
for(i=0;i<24;i++,p++) //ctime函数返回字符为24个
if(i>19&&i<24)
printf("%c",*p);
return (0);
}

int month_h() //显示月
{
char month_n[12][5]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
char *p;
char month[4]; //存放三个字符
int i,j=0;
p=time_ta();
for(i=0;i<24;i++,p++) //i<24因为ctime()函数返回有24个字符
{
if(i>=4 && i<7) //取ctime函数返回值的第5--8共三个字符.
{
month[j++]=*p;
if(j==3)
{
month[j]='\0';
break;

}
}
}
for (i=0;i<12;i++)
{
if (strcmp(month_n[i],month) == 0)
{
return (i+1);

}

}

return (13);

}

int date_e() //日
{
int j=0,i=0;
char date[2];
char *p;
p=time_ta();
for(i=0;i<24;i++,p++)
if(i>=8&&i<10)
{ date[j]=*p;
printf("%c",date[j++]);}
return 0;
}

int time_e() //时间
{ int i;
char *p;
p=time_ta();
for(i=0;i<24;i++,p++)
if(i>10&&i<19)
printf("%c",*p);
printf("\n");
return (0);
}
百度网友0be0b65
推荐于2020-12-09 · TA获得超过365个赞
知道小有建树答主
回答量:296
采纳率:0%
帮助的人:167万
展开全部
用这个吧,bldx123的版本太老了!
#include <stdio.h>
#include <windows.h>
#include <time.h>
get_time() //时间是从1900年开始算
{
struct tm *Tm;
time_t t;

time(&t);
Tm = localtime(&t);

printf("\n\n\n\t\t\t%d-%d-%d %d:%d:%d\n",Tm->tm_year+1900,Tm->tm_mon,Tm->tm_mday,Tm->tm_hour,Tm->tm_min,Tm->tm_sec);
return 0;
}

main()
{
for(;;)
{
get_time();
system("cls");//清屏
}
}
抢首赞 已赞过 已踩过<
你对这个回答的评价是?
评论 举报 收起
匿名用户
2011-05-26
展开全部
。。
抢首赞 已赞过 已踩过<
你对这个回答的评价是?
评论 举报 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式