htime.h 857 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #ifndef HW_TIME_H_
  2. #define HW_TIME_H_
  3. #include <time.h>
  4. #include "hplatform.h"
  5. typedef struct datetime_s {
  6. int year;
  7. int month;
  8. int day;
  9. int hour;
  10. int min;
  11. int sec;
  12. int ms;
  13. } datetime_t;
  14. #ifdef OS_WIN
  15. inline void sleep(unsigned int s) {
  16. Sleep(s*1000);
  17. }
  18. #endif
  19. inline void msleep(unsigned int ms) {
  20. #ifdef OS_WIN
  21. Sleep(ms);
  22. #else
  23. usleep(ms*1000);
  24. #endif
  25. }
  26. // ms
  27. inline unsigned int gettick() {
  28. #ifdef OS_WIN
  29. return GetTickCount();
  30. #else
  31. struct timeval tv;
  32. gettimeofday(&tv, NULL);
  33. return tv.tv_sec*1000 + tv.tv_usec/1000;
  34. #endif
  35. }
  36. // us
  37. inline unsigned int getclock() {
  38. return clock()*(unsigned long long)1000000 / CLOCKS_PER_SEC;
  39. }
  40. int month_atoi(const char* month);
  41. const char* month_itoa(int month);
  42. datetime_t get_datetime();
  43. datetime_t get_compile_datetime();
  44. #endif // HW_TIME_H_