在dos头文件中有一个time结构:
struct time {
unsigned char ti_min; /* Minutes */
unsigned char ti_hour; /* Hours */
unsigned char ti_hund; /* Hundredths of seconds */
unsigned char ti_sec; /* Seconds */
};
在程序中就可以包含头文件dos,然后直接使用这个结构就可以,然后用gettime()获的时间!!!
函数名: gettime
功 能: 取得系统时间
用 法: void gettime(struct time *timep);
程序例:
#include
#include
int main(void)
{
struct time t;
gettime(&t);
printf("The current time is: %2d:%02d:%02d.%02d\n",
t.ti_hour, t.ti_min, t.ti_sec, t.ti_hund);
return 0;
}
函数名: settime
功 能: 设置系统时间
用 法: void settime(struct time *timep);
程序例:
#include
#include
int main(void)
{
struct time t;
gettime(&t);
printf("The current minute is: %d\n", t.ti_min);
printf("The current hour is: %d\n", t.ti_hour);
printf("The current hundredth of a second is: %d\n", t.ti_hund);
printf("The current second is: %d\n", t.ti_sec);
/* Add one to the minutes struct element and then call settime */
t.ti_min++;
settime(&t);
return 0;
}