time.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. *
  3. * NMEA library
  4. * URL: http://nmea.sourceforge.net
  5. * Author: Tim (xtimor@gmail.com)
  6. * Licence: http://www.gnu.org/licenses/lgpl.html
  7. * $Id: time.c 4 2007-08-27 13:11:03Z xtimor $
  8. *
  9. */
  10. /*! \file time.h */
  11. #include "nmea/time.h"
  12. #ifdef NMEA_WIN
  13. # pragma warning(disable: 4201)
  14. # pragma warning(disable: 4214)
  15. # pragma warning(disable: 4115)
  16. # include <windows.h>
  17. # pragma warning(default: 4201)
  18. # pragma warning(default: 4214)
  19. # pragma warning(default: 4115)
  20. #else
  21. # include <time.h>
  22. #endif
  23. #ifdef NMEA_WIN
  24. void nmea_time_now(nmeaTIME *stm)
  25. {
  26. SYSTEMTIME st;
  27. GetSystemTime(&st);
  28. stm->year = st.wYear - 1900;
  29. stm->mon = st.wMonth - 1;
  30. stm->day = st.wDay;
  31. stm->hour = st.wHour;
  32. stm->min = st.wMinute;
  33. stm->sec = st.wSecond;
  34. stm->hsec = st.wMilliseconds / 10;
  35. }
  36. #else /* NMEA_WIN */
  37. void nmea_time_now(nmeaTIME *stm)
  38. {
  39. time_t lt;
  40. struct tm *tt;
  41. time(&lt);
  42. tt = gmtime(&lt);
  43. stm->year = tt->tm_year;
  44. stm->mon = tt->tm_mon;
  45. stm->day = tt->tm_mday;
  46. stm->hour = tt->tm_hour;
  47. stm->min = tt->tm_min;
  48. stm->sec = tt->tm_sec;
  49. stm->hsec = 0;
  50. }
  51. #endif