home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / sysutl / dtime.arc / DTIME.C next >
Text File  |  1989-05-17  |  2KB  |  40 lines

  1.  
  2. #include <time.h>
  3. #include <stddef.h>
  4. static char *days[]= {"Monday","Tuesday","Wednesday","Thursday","Friday",
  5.               "Saturday","Sunday"
  6.              };
  7. static char *mont[]= {"January","February","March","April","May","June",
  8.               "July","August","September","October","November",
  9.               "December"
  10.              };
  11. main(argc)
  12. int argc;              /* Command line option to include time */
  13. {
  14. register int i;              /* Used to find the expanded month and day */
  15. char bufr[40];              /* A place to hold the date string */
  16. char cmon[10],cday[10],ctime[10]; /* Storage for the month,day, and time */
  17. int  nday,nyear;          /* Storage for the numeric day and year */
  18. struct tm *ptr;              /* A pointer to a "time" structure */
  19. time_t lt;
  20.  
  21.     lt=time(NULL);            /* Setup for "time" call     */
  22.     ptr=localtime(<);        /* Get the system time from DOS */
  23.     strcpy(bufr,asctime(ptr));      /* Place string in the buffer   */
  24.     sscanf(bufr,"%s %s %d %s %d",cday,cmon,&nday,ctime,&nyear);
  25.  
  26.     ctime[strlen(ctime)-3]='\0';   /* Strip off the hundreths of seconds */
  27.     for(i=0;i<7;i++)                  /* Find the day of the week */
  28.       if(strncmp(days[i],cday,3)==0)
  29.          break;
  30.     strcpy(cday,days[i]);          /* And spell the whole thing out */
  31.     for(i=0;i<12;i++)                 /* Find the month of the year */
  32.       if(strncmp(mont[i],cmon,3)==0)
  33.          break;
  34.     strcpy(cmon,mont[i]);           /* And spell the whole thing out */
  35.     if(argc!=2)               /* See if you wanted the time output */
  36.         printf("%s %d, %d\t%s\n",cmon,nday,nyear,cday);
  37.       else
  38.         printf("%s %d, %d\t%s %s\n",cmon,nday,nyear,cday,ctime);
  39. }
  40.