30.10.2014 Views

o_195h4n6al16jb186b1b2qs7fgssa.pdf

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Language Tools Libraries<br />

DS51456B-page 320<br />

difftime<br />

2004 Microchip Technology Inc.<br />

Description: Find the difference between two times.<br />

Include: <br />

Prototype: double difftime(time_t t1, time_t t0);<br />

Arguments: t1 ending time<br />

t0 beginning time<br />

Return Value: Returns the number of seconds between t1and t0.<br />

Remarks: By default, MPLAB C30 returns the time as instruction cycles so<br />

difftimereturns the number of ticks between t1and t0.<br />

Example: #include /*for clock, difftime */<br />

#include /* for printf */<br />

volatile int i;<br />

int main(void)<br />

{<br />

clock_t start, stop;<br />

double elapsed;<br />

start = clock();<br />

for (i = 0; i < 10; i++)<br />

stop = clock();<br />

printf("start = %ld\n", start);<br />

printf("stop = %ld\n", stop);<br />

elapsed = difftime(stop, start);<br />

printf("Elapsed time = %.0f\n", elapsed);<br />

}<br />

Output:<br />

start = 0<br />

stop = 317<br />

Elapsed time = 317<br />

gmtime<br />

Description: Converts calendar time to time structure expressed as Universal<br />

Time<br />

Coordinated (UTC) also known asGreenwich Mean Time (GMT).<br />

Include: <br />

Prototype: struct tm *gmtime(const time_t *tod);<br />

Argument: tod pointer to stored time<br />

Return Value: Returns the address of the time structure.<br />

Remarks: This function breaks down the todvalue into the time structure of type<br />

% P AM / PM vấn thiết kế<br />

% S thứ hai của phút (00-61)<br />

cho phép đến hai giây nhuận<br />

% U số tuần của năm mà Chủ nhật là ngày đầu tiên của tuần 1<br />

(00-53)<br />

% W ngày trong tuần, nơi Chủ nhật là ngày 0 (0-6)<br />

% W số tuần trong năm, nơi thứ hai là ngày đầu tiên của tuần 1<br />

(00-53)<br />

% X đại diện ngày thích hợp<br />

% X đại diện thời điểm thích hợp<br />

% Năm y mà không cần thế kỷ (00-99)<br />

% Y năm với thế kỷ<br />

Khu% Z thời gian (có thể viết tắt) hoặc không có ký tự nếu múi giờ là<br />

không có sẵn<br />

%% Tính phần trăm%<br />

Ví dụ: # include / * Cho strftime, * /<br />

/ * Localtime, * /<br />

/ * Time_t, tm * /<br />

# include / * Cho printf * /<br />

int main (void)<br />

{<br />

giờ time_t, whattime;<br />

struct tm * Newtime;<br />

char buf [128];<br />

timer = 1066668182; / * Thứ 16:43:02 ngày 20 tháng 10 năm 2003 * /<br />

/ * Localtime phân bổ không gian cho cấu trúc * /<br />

Newtime = localtime (và thời gian);<br />

strftime (buf, 128, "Đó là một% A,% d ngày vào"<br />

". Tháng% B trong năm% Y \ n", Newtime);<br />

printf (buf);<br />

strftime (buf, 128, "Đó là tuần W% vào năm"<br />

"Hoặc jdays% vào năm \ n.", Newtime);<br />

printf (buf);<br />

}<br />

Đầu ra:<br />

Đó là một thứ hai, 20 ngày vào tháng Mười năm<br />

năm 2003.<br />

Đó là 42 tuần vào năm hoặc 293 ngày vào<br />

năm.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!