home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / j / julian11.zip / DATEJFM.C < prev    next >
Text File  |  1993-01-11  |  2KB  |  52 lines

  1. #include "julian.h"
  2.  
  3. // ===== D A T E _ F M _ J U L
  4. // Is passed a time_t (long) and converts it to a date
  5. //
  6. // dateret_stp - the date string returned
  7. // juldate     - the date in julian (long) form
  8. // format_stp  - the format that dateret_stp will be returned as
  9. //
  10. int date_fm_jul(char *dateret_stp,time_t juldate, char *format_stp)
  11. {
  12.    struct tm *timeptr;
  13.  
  14.    timeptr = localtime(&juldate);
  15.  
  16.   if (strcmp(format_stp,"YY/MM/DD") == 0){
  17.     sprintf(dateret_stp,"%02d/%02d/%02d",timeptr->tm_year,
  18.                                          timeptr->tm_mon+1,
  19.                                          timeptr->tm_mday);
  20.   }
  21.   else if (strcmp(format_stp,"MM/DD/YY") == 0){
  22.     sprintf(dateret_stp,"%02d/%02d/%02d",timeptr->tm_mon+1,
  23.                                          timeptr->tm_mday,
  24.                                          timeptr->tm_year);
  25.   }
  26.   else if (strcmp(format_stp,"YYMMDD") == 0){
  27.     sprintf(dateret_stp,"%02d%02d%02d",timeptr->tm_year,
  28.                                        timeptr->tm_mon+1,
  29.                                        timeptr->tm_mday);
  30.   }
  31.   else if (strcmp(format_stp,"MMDDYY") == 0){
  32.     sprintf(dateret_stp,"%02d%02d%02d",timeptr->tm_mon+1,
  33.                                        timeptr->tm_mday,
  34.                                        timeptr->tm_year);
  35.   }
  36.   else if (strcmp(format_stp,"YYYYMMDD") == 0){
  37.     if (timeptr->tm_year < 80)    
  38.       sprintf(dateret_stp,"%04d%02d02d",timeptr->tm_year+2000,
  39.                                         timeptr->tm_mon+1,
  40.                                         timeptr->tm_mday);
  41.     else
  42.       sprintf(dateret_stp,"%04d%02d%02d",timeptr->tm_year+1900,
  43.                                          timeptr->tm_mon+1,
  44.                                          timeptr->tm_mday);
  45.   }
  46.   else{
  47.     printf("Invalid date picture.\n");
  48.     return(1);
  49.   }
  50.   return(0);
  51. }
  52.