htime.h 839 B

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