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

  1. /***
  2. *strtime.c - contains the function "_strtime()"
  3. *
  4. *       Copyright (c) 1989-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       contains the function _strtime()
  8. *
  9. *******************************************************************************/
  10.  
  11.  
  12. #include <cruntime.h>
  13. #include <time.h>
  14. #include <tchar.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 *_strtime(buffer) - return time in string form
  27. *
  28. *Purpose:
  29. *       _strtime() returns a string containing the time in "HH:MM:SS" form
  30. *
  31. *Entry:
  32. *       _TSCHAR *buffer = the address of a 9-byte user buffer
  33. *
  34. *Exit:
  35. *       returns buffer, which contains the time in "HH:MM:SS" form
  36. *
  37. *Exceptions:
  38. *
  39. *******************************************************************************/
  40.  
  41. _TSCHAR * __cdecl _tstrtime (
  42.         _TSCHAR *buffer
  43.         )
  44. {
  45.         int hours, minutes, seconds;
  46.  
  47. #ifdef _WIN32
  48.         SYSTEMTIME dt;                       /* Win32 time structure */
  49.         GetLocalTime(&dt);
  50.  
  51.         hours = dt.wHour;
  52.         minutes = dt.wMinute;
  53.         seconds = dt.wSecond;
  54. #else  /* _WIN32 */
  55. #if defined (_M_MPPC) || defined (_M_M68K)
  56.         DateTimeRec dt;
  57.         GetTime(&dt);
  58.  
  59.         hours = dt.hour;
  60.         minutes = dt.minute;
  61.         seconds = dt.second;
  62. #endif  /* defined (_M_MPPC) || defined (_M_M68K) */
  63. #endif  /* _WIN32 */
  64.  
  65.         /* store the components of the time into the string */
  66.         /* store separators */
  67.         buffer[2] = buffer[5] = _T(':');
  68.         /* store end of string */
  69.         buffer[8] = _T('\0');
  70.         /* store tens of hour */
  71.         buffer[0] = (_TSCHAR) (hours   / 10 + _T('0'));
  72.         /* store units of hour */
  73.         buffer[1] = (_TSCHAR) (hours   % 10 + _T('0'));
  74.         /* store tens of minute */
  75.         buffer[3] = (_TSCHAR) (minutes / 10 + _T('0'));
  76.         /* store units of minute */
  77.         buffer[4] = (_TSCHAR) (minutes % 10 + _T('0'));
  78.         /* store tens of second */
  79.         buffer[6] = (_TSCHAR) (seconds / 10 + _T('0'));
  80.         /* store units of second */
  81.         buffer[7] = (_TSCHAR) (seconds % 10 + _T('0'));
  82.  
  83.         return buffer;
  84. }
  85.  
  86.