1 #include "stdio.h"
2 #include "time.h"
3 #include "dos.h"
4 #include "windows.h"
5 #include "string.h"
6 #include "ctype.h"
7
8 int year_r(); //显示年
9 int month_h(); //月
10 int date_e(); //日
11 int time_e(); //时间
12 char * time_ta(); //将日期时间转换成字符串
13 int wait_t(); //延时1秒
14
15 char * time_ta() //将日期时间转换成字符串
16 {
17 char *q;
18 time_t t;
19 t=time(NULL);
20 q=ctime(&t);
21 //printf("*q_address = 0x%x\n",q);
22 return (q);
23 }
24
25 int wait_t() //延时1秒
26 {
27 long temp_total=0;
28 time_t time_temp;
29 time_temp=time(NULL);
30 temp_total=time_temp;
31 for(;;)
32 {
33 time_temp=time(NULL);
34 if(abs(time_temp - temp_total) >=1)
35 break;
36 }
37
38 return (0);
39 }
40
41 int main()
42 {
43 int temp;
44
45 system("cls"); //清屏
46 printf("\n\n\n\n\n\n\n\n\t\t\t");
47 year_r();
48 printf("年");
49 temp = month_h();
50 if (temp != 13)
51 {
52 printf("%d",temp);
53 printf("月");
54 }
55 else printf("month error!\n");
56 date_e();
57 printf("日");
58 time_e();
59 printf("\r");
60 for(;;) //显示年月日时分秒
61 {
62 wait_t(); // 1秒钟到显示年月日时分秒
63 system("cls");
64 printf("\n\n\n\n\n\n\n\n\t\t\t");
65 year_r();
66 printf("年");
67 temp = month_h();
68 if (temp != 13)
69 {
70 printf("%d",temp);
71 printf("月");
72 }
73 else printf("month error!\n");
74
75 date_e();
76 printf("日");
77 time_e();
78 }
79 getchar();
80
81 }
82
83 int year_r() //显示年
84 {
85
86 char *p;
87 int i;
88 p=time_ta();
89 for(i=0;i<24;i++,p++) //ctime函数返回字符为24个
90 if(i>19&&i<24)
91 printf("%c",*p);
92 return (0);
93 }
94
95 int month_h() //显示月
96 {
97 char month_n[12][5]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
98 char *p;
99 char month[4]; //存放三个字符
100 int i,j=0;
101 p=time_ta();
102 for(i=0;i<24;i++,p++) //i<24因为ctime()函数返回有24个字符
103 {
104 if(i>=4 && i<7) //取ctime函数返回值的第5--8共三个字符.
105 {
106 month[j++]=*p;
107 if(j==3)
108 {
109 month[j]='\0';
110 break;
111
112 }
113 }
114 }
115 for (i=0;i<12;i++)
116 {
117 if (strcmp(month_n[i],month) == 0)
118 {
119 return (i+1);
120
121 }
122
123 }
124
125 return (13);
126
127 }
128
129 int date_e() //日
130 {
131 int j=0,i=0;
132 char date[2];
133 char *p;
134 p=time_ta();
135 for(i=0;i<24;i++,p++)
136 if(i>=8&&i<10)
137 { date[j]=*p;
138 printf("%c",date[j++]);}
139 return 0;
140 }
141
142 int time_e() //时间
143 { int i;
144 char *p;
145 p=time_ta();
146 for(i=0;i<24;i++,p++)
147 if(i>10&&i<19)
148 printf("%c",*p);
149 printf("\n");
150 return (0);
151 }
1 #include <iostream>
2 #include <windows.h>
3 using namespace std;
4 int main()
5 {
6 SYSTEMTIME sys;
7 do
8 {
9 GetLocalTime(&sys);
10 cout<<sys.wHour<<":"<<sys.wMinute<<":"<<sys.wSecond;
11 Sleep(1000);
12 system("cls");
13 }while(1);
14 return 0;
15 }