uTools-Manuals/docs/c/time.html
2019-04-21 11:50:48 +08:00

62 lines
1.6 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<h1>标准库函数 - time</h1>
<p>原型extern int time(struct tm *pTime);</p>
<p>用法:#include &lt;system.h></p>
<p>功能:取得系统时间</p>
<p>说明结构tm在system.h中定义</p>
<pre><code class="language-c">
struct tm
{
int hsec; /* Half Seconds. [0-119] */
int sec; /* Seconds [0-59] */
int min; /* Minutes [0-59] */
int hour; /* Hours [0-23] */
int day; /* Day [0-30] */
int wday; /* Day of Week [0-6] */
int mon; /* Month [0-11] */
int year; /* Year - 1881 */
};
</code></pre>
举例:<pre><code class="language-c">
// timec
#include &lt;system.h>
#define CPR 14
main()
{
struct tm t1,t2;
char wday[][3]={"日","一","二","三","四","五","六"};
clrscr();
textmode(0xE0);
time(&t2);
while(!kbhit())
{
noidle();
time(&t1);
if(t1.hsec==t2.hsec) continue;
t2.hsec=t1.hsec;
move(1,1);
printf("%d年%2d月%2d日",t1.year+1881,t1.mon+1,t1.day+1);
move(2,(CPR-8)/2+1);
printf("%d:%d%d:%d%d",t1.hour,t1.min/10,t1.min%10,t1.sec/10,t1.sec%10);
move(3,2);
printf("今天是星期%s",wday[t1.wday]);
}
return 0;
}
</code></pre>相关函数:无