htime.h 818 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #ifndef HW_TIME_H_
  2. #define HW_TIME_H_
  3. #include "hplatform.h"
  4. typedef struct datetime_s {
  5. int year;
  6. int month;
  7. int day;
  8. int hour;
  9. int min;
  10. int sec;
  11. int ms;
  12. } datetime_t;
  13. #ifdef OS_WIN
  14. inline void sleep(unsigned int s) {
  15. Sleep(s*1000);
  16. }
  17. #endif
  18. inline void msleep(unsigned int ms) {
  19. #ifdef OS_WIN
  20. Sleep(ms);
  21. #else
  22. usleep(ms*1000);
  23. #endif
  24. }
  25. // ms
  26. inline unsigned int gettick() {
  27. #ifdef OS_WIN
  28. return GetTickCount();
  29. #else
  30. return clock()*(unsigned long long)1000 / CLOCKS_PER_SEC;
  31. #endif
  32. }
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  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_