fork download
  1. #include <stdio.h>
  2. #include <time.h>
  3.  
  4. char *c89_asctime(const struct tm *timeptr)
  5. {
  6. static const char wday_name[7][3] = {
  7. "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
  8. };
  9. static const char mon_name[12][3] = {
  10. "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  11. "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
  12. };
  13. static char result[26];
  14.  
  15. sprintf(result, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n",
  16. wday_name[timeptr->tm_wday],
  17. mon_name[timeptr->tm_mon],
  18. timeptr->tm_mday, timeptr->tm_hour,
  19. timeptr->tm_min, timeptr->tm_sec,
  20. 1900 + timeptr->tm_year);
  21. return result;
  22. }
  23.  
  24.  
  25. int main(void) {
  26. struct tm broken_down;
  27. broken_down.tm_year = 2000 - 1900;
  28. broken_down.tm_mon = 0;
  29. broken_down.tm_mday = 1;
  30. broken_down.tm_hour = broken_down.tm_min = broken_down.tm_sec = 0;
  31.  
  32. printf("Current date and time: %s", asctime(&broken_down));
  33. printf("C89 asctime result is: %s", c89_asctime(&broken_down));
  34. }
Success #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
Current date and time: Sun Jan  1 00:00:00 2000
C89 asctime result is: Sun Jan  1 00:00:00 2000