home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / strdate.c < prev    next >
C/C++ Source or Header  |  1998-06-17  |  2KB  |  91 lines

  1. /***
  2. *strdate.c - contains the function "_strdate()"
  3. *
  4. *       Copyright (c) 1989-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       contains the function _strdate()
  8. *
  9. *******************************************************************************/
  10.  
  11.  
  12. #include <cruntime.h>
  13. #include <tchar.h>
  14. #include <time.h>
  15.  
  16. #ifdef _WIN32
  17. #include <oscalls.h>
  18. #else  /* _WIN32 */
  19. #if defined (_M_MPPC) || defined (_M_M68K)
  20. #include <macos\osutils.h>      /* get DataTimeRec type */
  21. #endif  /* defined (_M_MPPC) || defined (_M_M68K) */
  22. #endif  /* _WIN32 */
  23.  
  24.  
  25. /***
  26. *_TSCHAR *_strdate(buffer) - return date in string form
  27. *
  28. *Purpose:
  29. *       _strdate() returns a string containing the date in "MM/DD/YY" form
  30. *
  31. *Entry:
  32. *       _TSCHAR *buffer = the address of a 9-byte user buffer
  33. *
  34. *Exit:
  35. *       returns buffer, which contains the date in "MM/DD/YY" form
  36. *
  37. *Exceptions:
  38. *
  39. *******************************************************************************/
  40.  
  41. _TSCHAR * __cdecl _tstrdate (
  42.         _TSCHAR *buffer
  43.         )
  44. {
  45.         int month, day, year;
  46.  
  47. #ifdef _WIN32
  48.  
  49.         SYSTEMTIME dt;                       /* Win32 time structure */
  50.  
  51.         GetLocalTime(&dt);
  52.         month = dt.wMonth;
  53.         day = dt.wDay;
  54.         year = dt.wYear % 100;          /* change year into 0-99 value */
  55.  
  56. #else  /* _WIN32 */
  57. #if defined (_M_MPPC) || defined (_M_M68K)
  58.  
  59.         DateTimeRec dt;
  60.  
  61.         GetTime(&dt);
  62.  
  63.         month = dt.month;
  64.         day = dt.day;
  65.         year = dt.year % 100;
  66.  
  67. #endif  /* defined (_M_MPPC) || defined (_M_M68K) */
  68. #endif  /* _WIN32 */
  69.  
  70.         /* store the components of the date into the string */
  71.         /* store seperators */
  72.         buffer[2] = buffer[5] = _T('/');
  73.         /* store end of string */
  74.         buffer[8] = _T('\0');
  75.         /* store tens of month */
  76.         buffer[0] = (_TSCHAR) (month / 10 + _T('0'));
  77.         /* store units of month */
  78.         buffer[1] = (_TSCHAR) (month % 10 + _T('0'));
  79.         /* store tens of day */
  80.         buffer[3] = (_TSCHAR) (day   / 10 + _T('0'));
  81.         /* store units of day */
  82.         buffer[4] = (_TSCHAR) (day   % 10 + _T('0'));
  83.         /* store tens of year */
  84.         buffer[6] = (_TSCHAR) (year  / 10 + _T('0'));
  85.         /* store units of year */
  86.         buffer[7] = (_TSCHAR) (year  % 10 + _T('0'));
  87.  
  88.         return buffer;
  89. }
  90.  
  91.