home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / zip / gnu / mntlib16.lzh / MNTLIB16 / CTIME.C < prev    next >
C/C++ Source or Header  |  1993-07-29  |  2KB  |  47 lines

  1. #include <time.h>
  2. #include <string.h>
  3. #include <stdio.h>
  4.  
  5. /* taken from Dale Schumacher's dLibs library */
  6.  
  7. static char             timebuf[26];
  8.  
  9. static char             *day[] =
  10.                         {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
  11. static char             *month[] =
  12.                         {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
  13.                         "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
  14.  
  15.  
  16. char *asctime(time)
  17.         register const struct tm *time;
  18. /*
  19.  *      Convert <time> structure value to a string.  The same format, and
  20.  *      the same internal buffer, as for ctime() is used for this function.
  21.  */
  22.         {
  23.     if (time == NULL)
  24.          (void)strcpy(timebuf, "??? ??? ?? ??:??:?? ????\n");
  25.     else
  26.              (void)sprintf(timebuf, "%.3s %.3s%3d %02d:%02d:%02d %04d\n",
  27.                 day[time->tm_wday], month[time->tm_mon], time->tm_mday,
  28.                 time->tm_hour, time->tm_min, time->tm_sec, 1900+time->tm_year);
  29.         return(timebuf);
  30.         }
  31.  
  32. char *ctime(rawtime)
  33.         const time_t *rawtime;
  34. /*
  35.  *      Convert <rawtime> to a string.  A 26 character fixed field string
  36.  *      is created from the raw time value.  The following is an example
  37.  *      of what this string might look like:
  38.  *              "Wed Jul 08 18:43:07 1987\n\0"
  39.  *      A 24-hour clock is used, and due to a limitation in the ST system
  40.  *      clock value, only a resolution of 2 seconds is possible.  A pointer
  41.  *      to the formatted string, which is held in an internal buffer, is
  42.  *      returned.
  43.  */
  44.         {
  45.         return(asctime(localtime(rawtime)));
  46.         }
  47.