- 計算時間差函數 double difftime(time_t time2,time_t time1);
#include<stdio.h>
#include<time.h>
#include<dos.h>
#include<conio.h>
int main()
{
time_t first, second;
clrscr();
first = time(NULL);
delay(3000);
second = time(NULL);
printf("The interval is : %f seconds\n",difftime(second,first));
getch();
return 0;
}
- gmtime 將日曆轉換成GMT (格林尼治時間)
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
int main(void)
{
time_t t;
struct tm *gmt;
t = time(NULL);
gmt = gmtime(&t);
printf("GMT is %s",asctime(gmt));
return 0;
}
- 與上一個函數這號相反: localtime() 將 日曆時間轉換結構體類型時間
#include<stdio.h>
#include<time.h>
#include<dos.h>
int main(void)
{
time_t timer;
struct tm *tblock;
timer = time(NULL);
tblock = localtime(&timer);
printf("Local time is: %s\n",asctime(tblock));
printf("Today's date and time:%s\n",ctime(&timer));
getch();
return 0;
}
注:
dos.h 請點擊查看
conio.h 包含函數如下:
cgets(char*);;
cputs(constchar*);
cscanf(constchar*,...);
inpw(unsignedshort);
getch(void);
getche(void);
kbhit(void);
outp(unsignedshort,int);
outpw(unsignedshort,unsignedshort);
putch(int);
ungetch(int);
void_Cdeclclreol(void);
void_Cdeclclrscr(void);
void_Cdecldelline(void);
int_Cdeclgettext(intleft,inttop,intright,intbottom,void*destin);
void_Cdeclgettextinfo(structtext_info*r);
void_Cdeclgotoxy(intx,inty);
void_Cdeclhighvideo(void);
void_Cdeclinsline(void);
void_Cdecllowvideo(void);
int_Cdeclmovetext(intleft,inttop,intright,intbottom,intdestleft,intdesttop);
void_Cdeclnormvideo(void);
int_Cdeclputtext(intleft,inttop,intright,intbottom,void*source);
void_Cdecltextattr(intnewattr);
void_Cdecltextbackground(intnewcolor);
void_Cdecltextcolor(intnewcolor);
void_Cdecltextmode(intnewmode);
int_Cdeclwherex(void);
int_Cdeclwherey(void);
void_Cdeclwindow(intleft,inttop,intright,intbottom);
char*_Cdeclcgets(char*str);
int_Cdeclcprintf(constchar*format,...);
int_Cdeclcputs(constchar*str);
int_Cdeclcscanf(constchar*format,...);
int_Cdeclgetch(void);
int_Cdeclgetche(void);
char*_Cdeclgetpass(constchar*prompt);
int_Cdeclkbhit(void);
int_Cdeclputch(intc);
int_Cdeclungetch(intch);