以下程式示範使用 mktime() 的結果
#include <stdio.h>
#include <time.h>
int main(void)
{
time_t n;
struct tm t1;
t1.tm_sec = 8;
t1.tm_min = 12;
t1.tm_hour = 3;
t1.tm_mday = 22;
t1.tm_mon = 3;
t1.tm_year = 1999-1900;
t1.tm_wday = 1;
t1.tm_yday = 81;
t1.tm_isdst = -1;
n = mktime(&t1);
printf("西元 1999 年 3 月 22 日 3 點 12 分 8 秒共累計了 %u 秒....\n", n);
return 0;
}
/* 《程式語言教學誌》的範例程式
http://pydoing.blogspot.com/
檔名:cmktime.c
功能:示範 time.h 中函數 mktime() 的使用
作者:張凱慶
時間:西元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);
沒有留言:
張貼留言