mktime.c (472B)
1 #include <time.h> 2 3 static int mday[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; 4 5 time_t mktime(const struct tm *tm) 6 { 7 int i; 8 time_t t = 0; 9 for(i=70; i<tm->tm_year; i++){ 10 if(i%4 == 0) 11 t += 86400 * 366; 12 else 13 t += 86400 * 365; 14 } 15 for(i=0; i<tm->tm_mon; i++){ 16 t += mday[i] * 86400; 17 if (tm->tm_year % 4 == 0 && i == 2) 18 t += 86400; 19 } 20 t += (tm->tm_mday-1) * 86400; 21 t += tm->tm_hour * 3600; 22 t += tm->tm_min * 60; 23 t += tm->tm_sec; 24 return t; 25 }