home *** CD-ROM | disk | FTP | other *** search
/ pc.louisiana.edu/pub/unix/ / Louisiana_UNIX.tar / Louisiana_UNIX / date+.zoo / date+.c < prev    next >
C/C++ Source or Header  |  1991-10-15  |  900b  |  36 lines

  1. /* date+ ... similar to the date(1) program but converts an arbitrary date,
  2.    WITH offsets allowed.
  3.    USAGE:  date+  date_string  display_format_string
  4.    where date_string has the form mm/dd/yy [hh:mm:ss]  [number offset_units [ago]]
  5.     and display_format_string is that accepted by strftime().
  6.  
  7.    Adapted from Usenet Bnews' getdate.y by jpd@usl.edu 10 Nov 1991.
  8. */
  9. #include <stdio.h>
  10. #include <time.h>
  11. static char *rcsid = "@(#)date+ 1.0 10/15/91";
  12.  
  13. main(argc, argv)
  14. int argc;
  15. char *argv[];
  16. {
  17.     struct tm  *tmptr;
  18.     char buf[128];
  19.     time_t tim;
  20.  
  21.     if (argc != 3) {
  22.         fprintf(stderr, "Usage: date+  date_str fmt_str\n");
  23.         exit (1);
  24.     }
  25.  
  26.     tim = getdate(argv[1], NULL);
  27. #ifdef DEBUG
  28.     printf("ctime(getdate()) = %s\n", ctime(&tim));
  29. #endif
  30.  
  31.     tmptr = localtime(&tim);    /* longint to tm struct */
  32.         if (strftime(buf, sizeof(buf), argv[2], tmptr)==0) buf[0] = '\0';
  33.     printf("%s\n", buf);
  34.     exit(0);
  35. }
  36.