home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xntp3.zip / lib / humandate.c < prev    next >
C/C++ Source or Header  |  1992-07-07  |  834b  |  43 lines

  1. /*
  2.  * humandate - convert an NTP time to something readable
  3.  */
  4. #include <stdio.h>
  5. #include <sys/types.h>
  6. #include <sys/time.h>
  7. #ifdef RS6000
  8. #include <time.h>
  9. #endif
  10. #include <sys/socket.h>
  11. #include <netinet/in.h>
  12.  
  13. #include "ntp_fp.h"
  14. #include "ntp_unixtime.h"
  15. #include "lib_strbuf.h"
  16.  
  17. char *
  18. humandate(ntptime)
  19.     u_long ntptime;
  20. {
  21.     char *bp;
  22.     struct tm *tm;
  23.     u_long sec;
  24.     static char *months[] = {
  25.         "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  26.         "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
  27.     };
  28.     static char *days[] = {
  29.         "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
  30.     };
  31.  
  32.     LIB_GETBUF(bp);
  33.     
  34.     sec = ntptime - JAN_1970;
  35.     tm = localtime((long *)&sec);
  36.  
  37.     (void) sprintf(bp, "%s, %s %2d %4d %2d:%02d:%02d",
  38.         days[tm->tm_wday], months[tm->tm_mon], tm->tm_mday,
  39.         1900+tm->tm_year, tm->tm_hour, tm->tm_min, tm->tm_sec);
  40.     
  41.     return bp;
  42. }
  43.