asctime.c (894B)
1 #include <time.h> 2 #include <string.h> 3 4 static char *day[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; 5 static char *mon[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", 6 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; 7 8 char *asctime(const struct tm *tm) 9 { 10 static char buf[20]; 11 char *p; 12 13 p = buf; 14 memmove(p, day[tm->tm_wday], 3); 15 p += 3; 16 *p++ = ' '; 17 memmove(p, mon[tm->tm_mon], 3); 18 p += 3; 19 *p++ = ' '; 20 *p++ = '0' + tm->tm_mday / 10; 21 *p++ = '0' + tm->tm_mday % 10; 22 *p++ = ' '; 23 *p++ = '0' + tm->tm_hour / 10; 24 *p++ = '0' + tm->tm_hour % 10; 25 *p++ = ':'; 26 *p++ = '0' + tm->tm_min / 10; 27 *p++ = '0' + tm->tm_min % 10; 28 *p++ = ':'; 29 *p++ = '0' + tm->tm_sec / 10; 30 *p++ = '0' + tm->tm_sec % 10; 31 *p++ = ' '; 32 int y = tm->tm_year + 1900; 33 *p++ = '0' + y / 1000; 34 *p++ = '0' + (y / 100) % 10; 35 *p++ = '0' + (y / 10) % 10; 36 *p++ = '0' + y % 10; 37 *p++ = '\n'; 38 *p = 0; 39 40 return buf; 41 }