更新时间:2023-09-19 15:33:04
localtime()
函数使用指向 const time_t
的指针,因此您必须先将整数纪元值转换为 time_t
,然后再调用 localtime
。
The localtime()
function takes a pointer to const time_t
so you have to first convert your integer epoch value to a time_t
before calling localtime
.
int epoch_time = SOME_VALUE;
struct tm * timeinfo;
/* Conversion to time_t as localtime() expects a time_t* */
time_t epoch_time_as_time_t = epoch_time;
/* Call to localtime() now operates on time_t */
timeinfo = localtime(&epoch_time_as_time_t);