#include <stdio.h>
#include <stdlib.h>
#include <time.h>
enum Week{ MON=1, TUE, WED, THU, FRI, SAT, SUN};
enum Month{January=1,February,March,April,May,June,July,August,September,October,November,December};
struct Time
{
unsigned int year;
enum Month month;
unsigned char day;
enum Week week;
unsigned char hour;
unsigned char min;
unsigned char sec;
};
void delay(unsigned int x)
{
while(x)
{
x--;
unsigned int a,b;
for(a=0;a<20000;a++)
for(b=0;b<20000;b++);
}
}
struct Time time;
void time_update(void)
{
if(++time.sec==60)
{
time.sec=0;
if(++time.min==60)
{
time.min=0;
if(++time.hour==24)
time.hour=0;
}
}
}
void time_display(void)
{
printf("%4d年%2d月%2d日\n",time.year,time.month,time.day);
if(time.week==7)
printf("星期日\n");
else printf("星期%d\n",time.week);
printf("%02d:%02d:%02d\n",time.hour,time.min,time.sec);
system("cls");
}
int main(void)
{
time.year=2020;
time.month=November;
time.day=22;
time.week=SUN;
time.hour=23;
time.min=40;
time.sec=10;
printf("index:");
while(1)
{
time_update();
time_display();
delay(10000);
}
return 0;
}
|