time.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. filesummary.CH: 提供时间操作函数
  3. filesummary.EN: Provide time operations
  4. CH: 理论上指的CPU一秒内时钟数,现用于clock函数计算真实秒数
  5. EN: Theoretically refers to the number of clocks in one second of the CPU, which is now used in the clock function to calculate the real number of seconds
  6. */
  7. int CLOCKS_PER_SEC;
  8. /*
  9. CH: 用来保存时间和日期的结构
  10. EN: Structure to hold time and date
  11. */
  12. struct tm {
  13. builtin binary code
  14. };
  15. /*
  16. CH: 存储日历时间类型
  17. EN: Store calendar time type
  18. */
  19. typedef int time_t;
  20. /*
  21. CH: 存储处理器时间的类型,需要除CLOCKS_PER_SEC获得实际秒数
  22. EN: The type to store the processor time, needs to be divided by CLOCKS_PER_SEC to get the actual number of seconds
  23. */
  24. typedef int clock_t;
  25. /*
  26. CH: 返回一个指向字符串的指针,它代表了结构 struct timeptr 的日期和时间
  27. EN: Returns a pointer to a string representing the date and time of the structure struct timeptr
  28. */
  29. char* asctime(struct tm *timeptr);
  30. /*
  31. CH: 返回处理器时钟所使用的时间,需要除以 CLOCKS_PER_SEC
  32. EN: Returns the time used by the processor clock, divided by CLOCKS_PER_SEC
  33. */
  34. time_t clock();
  35. /*
  36. CH: 返回一个表示当地时间的字符串,当地时间是基于参数 timer
  37. EN: Returns a string representing the local time based on the parameter timer
  38. */
  39. char* ctime(time_t *timer);
  40. /*
  41. CH: 计算两个时间的差值
  42. EN: return the endTime - fromTime in seconds
  43. */
  44. double difftime(time_t endTime, time_t fromTime);
  45. /*
  46. CH: 使用 timer 的值来填充 tm 结构,并用协调世界时(UTC)也被称为格林尼治标准时间(GMT)表示
  47. EN: Populate the tm structure with the value of timer , expressed in Coordinated Universal Time (UTC) also known as Greenwich Mean Time (GMT)
  48. */
  49. struct tm* gmtime(time_t *timer);
  50. /*
  51. CH: 使用 timer 的值来填充 tm 结构。timer 的值被分解为 tm 结构,并用本地时区表示
  52. EN: Fill the tm structure with the value of timer. The value of timer is decomposed into a tm structure and expressed in the local time zone
  53. */
  54. struct tm* localtime(time_t *timer);
  55. /*
  56. CH: 将tm转换为time_t
  57. EN: Transfer tm to time_t
  58. */
  59. time_t mktime(struct tm *timePtr);
  60. /*
  61. CH: 得到当前日历时间或者设置日历时间
  62. EN: Get current calendar time or set calendar time
  63. */
  64. time_t time(time_t *timer);
  65. /*
  66. CH: 根据 format 中定义的格式化规则,格式化结构 timeptr 表示的时间,并把它存储在 str 中
  67. EN: Formats the time represented by the structure timeptr according to the formatting rules defined in format and stores it in str.
  68. */
  69. int strftime(char *string, size_t maxSize, char *format, struct tm *timePtr);
  70. /*
  71. CH: 按照特定时间格式将字符串转换为时间类型
  72. EN: Convert a string to a time type according to a specific time format
  73. */
  74. char* strptime(char *string, char *format, struct tm *timePtr);
  75. /*
  76. CH: 等同于 gmtime (Thread Safe)
  77. EN: Same to gmtime (Thread Safe)
  78. */
  79. struct tm* gmtime_r(time_t *timePtr, struct tm *result);
  80. /*
  81. CH: 从tm转换为time_t
  82. EN: Transfer tm to time_t
  83. */
  84. int timegm(struct tm *timePtr);