以下程式示範使用 asctime() 的結果
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #include <stdio.h> #include <time.h> int main( void ) { time_t t1 = time (NULL); struct tm *nPtr = localtime (&t1); char *now = asctime (nPtr); printf (now); return 0; } /* 《程式語言教學誌》的範例程式 檔名:casctime.c 功能:示範 time.h 中函數 asctime() 的使用 作者:張凱慶 時間:西元2010年6月 */ |
編譯後執行,結果如下

您可以繼續參考
時間 time.h
- clock_t clock(void);
- time_t time(time_t* timer);
- double difftime(time_t timer2, time_t timer1);
- time_t mktime(struct tm* ptm);
- struct tm* localtime(const time_t* timer);
- char *(const struct tm* tmptr);
- char* ctime(const time_t* timer);
- size t strftime(char* s, size t n, const char* format, const struct tm* tptr);
沒有留言:
張貼留言