30.10.2014 Views

o_195h4n6al16jb186b1b2qs7fgssa.pdf

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

MMMis month of the year<br />

ddis day of the month<br />

hhis hour<br />

mmis minute<br />

ssis second<br />

YYYYis year<br />

Example: #include /*for asctime, tm */<br />

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

volatile int i;<br />

int main(void)<br />

{<br />

struct tm when;<br />

time_t whattime;<br />

when.tm_sec = 30;<br />

when.tm_min = 30;<br />

when.tm_hour = 2;<br />

when.tm_mday = 1;<br />

when.tm_mon = 1;<br />

when.tm_year = 103;<br />

whattime = mktime(&when);<br />

printf("Day and time is %s\n", asctime(&when));<br />

}<br />

Output:<br />

Đối số: con trỏ tod gian lưu trữ<br />

Quay trở lại giá trị: Trả về địa chỉ cơ cấu thời gian.<br />

Ghi chú: Theo mặc định, MPLAB C30 trả về chu kỳ hướng dẫn timeas. Với<br />

điều này<br />

localtimeand mặc định gmtimewill tương đương trừ localtime<br />

sẽ trở lại tm_isdst (Daylight Savings Time cờ) là -1 để chỉ ra rằng<br />

tình trạng của Daylight Savings Time không được biết đến.<br />

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

/ * Asctime, time_t, tm * /<br />

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

int main (void)<br />

{<br />

giờ time_t;<br />

struct tm * Newtime;<br />

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

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

printf ("Giờ địa phương =% s \ n", asctime (Newtime));<br />

}<br />

Đầu ra:<br />

Giờ địa phương = Thứ Oct20 2003 16:43:02<br />

gmtime (Tiếp theo)<br />

dsPIC<br />

®<br />

Thư viện Công cụ Ngôn ngữ<br />

Day and time is Sat Feb 1 02:30:30 2003<br />

clock<br />

DS51456B trang 322<br />

mktime<br />

2004 Microchip Technology Inc<br />

Description: Calculates the processor time.<br />

Include: <br />

Prototype: clock_t clock(void);<br />

Return Value: Returns the number of clock ticks of elapsed processor time.<br />

Remarks: If the target environment cannot measure elapsed processor time, the<br />

function returns -1, cast as a clock_t. (i.e. (clock_t) -1) By default,<br />

MPLAB C30 returns the time as instruction cycles.<br />

Standard C Libraries with Math Functions<br />

2004 Microchip Technology Inc. DS51456B-page 319<br />

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

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

volatile int i;<br />

int main(void)<br />

{<br />

Mô tả: Chuyển đổi giờ địa phương đến một giá trị lịch.<br />

Bao gồm:<br />

Prototype: time_t mktime (struct tm * tptr);<br />

Đối số: tptr một con trỏ đến cấu trúc thời gian<br />

Quay trở lại giá trị: Trả lại thời gian lịch được mã hóa như là một giá trị time_t.<br />

Ghi chú: Nếu thời gian lịch không thể được đại diện, chức năng trả về -1, diễn<br />

viên<br />

như một time_t (tức là (time_t) -1).<br />

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

/ * Asctime, mktime, * /<br />

/ * Time_t, tm * /<br />

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

int main (void)<br />

{

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

Saved successfully!

Ooh no, something went wrong!