home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / pcmagazi / 1992 / 09 / datetime.c < prev    next >
C/C++ Source or Header  |  1992-01-12  |  2KB  |  96 lines

  1. // datetime.c RHS 1/15/92
  2.  
  3. #include<stdio.h>
  4.  
  5. #if !defined(TRUE)
  6. #define TRUE 1
  7. #endif
  8.  
  9. #if !defined(FALSE)
  10. #define FALSE 0
  11. #endif
  12.  
  13. #if defined(SMALL)
  14.  
  15. void GetDateTime(char *buf)
  16.     {
  17.     char *days[7] = 
  18.         { 
  19.         "Sunday", "Monday", "Tuesday", "Wednesday", 
  20.         "Thursday","Friday", "Saturday" 
  21.         };
  22.     char *months[12] = {
  23.         "January", "February", "March", "April", "May", "June",
  24.         "July", "August", "September", "October", "November", "December"
  25.         };   
  26.  
  27.     unsigned char month,day,dow;
  28.     unsigned char hour, minutes, seconds, hundredths;
  29.     unsigned char pm = FALSE;
  30.     unsigned year;
  31.  
  32. #if defined(__BORLANDC__)
  33.     _AH = 0x2A;
  34.     asm int 0x21;
  35.     dow = _AL;
  36.     year = _CX;
  37.     month = _DH;
  38.     day = _DL;
  39.     _AH = 0x2C;
  40.     asm int 0x21;
  41.     hour = _CH;
  42.     minutes = _CL;
  43.     seconds = _DH;
  44.     hundredths = _DL;
  45. #else
  46.     _asm mov ah,0x2a
  47.     _asm int 21h
  48.     _asm mov dow,al
  49.     _asm mov year,cx
  50.     _asm mov month,dh
  51.     _asm mov day,dl
  52.     _asm mov ah,0x2c
  53.     _asm int 21h
  54.     _asm mov hour,ch
  55.     _asm mov minutes,cl
  56.     _asm mov seconds,dh
  57.     _asm mov hundredths,dl
  58. #endif
  59.  
  60.     if(hour > 12)
  61.         {
  62.         pm = TRUE;
  63.         hour -= 12;
  64.         }
  65.     if(!hour)
  66.         hour = 12;
  67.  
  68.     sprintf(buf,"%s, %s %d, %04d, %d:%02d:%02d.%02d%s",
  69.         days[dow],months[month-1],day,year,hour,minutes,seconds,hundredths,
  70.         (pm ? "pm" : "am"));
  71.     }
  72.  
  73. #elif defined(BIG)
  74.  
  75. #include<time.h>
  76. void GetDateTime(char *buf)
  77.     {
  78.     time_t t;
  79.  
  80.     t = time(NULL);
  81.     sprintf(buf,"%s",ctime(&t));
  82.     }
  83. #else
  84. #error You must define SMALL or BIG in the program or on the command-line!
  85. #endif
  86.  
  87. void main(void)
  88.     {
  89.     char buf[50];
  90.  
  91.     GetDateTime(buf);
  92.     printf("%s\n",buf);
  93.     }
  94.  
  95.  
  96.