diff --git a/demo/os/linux/easylogger/port/elog_port.c b/demo/os/linux/easylogger/port/elog_port.c index 66ed238..e81d6b6 100755 --- a/demo/os/linux/easylogger/port/elog_port.c +++ b/demo/os/linux/easylogger/port/elog_port.c @@ -104,16 +104,14 @@ void elog_port_output_unlock(void) { */ const char *elog_port_get_time(void) { static char cur_system_time[24] = { 0 }; - time_t timep; - struct tm *p; - time(&timep); - p = localtime(&timep); - if (p == NULL) { - return ""; - } - snprintf(cur_system_time, 18, "%02d-%02d %02d:%02d:%02d", p->tm_mon + 1, p->tm_mday, - p->tm_hour, p->tm_min, p->tm_sec); + time_t cur_t; + struct tm cur_tm; + + time(&cur_t); + localtime_r(&cur_t, &cur_tm); + + strftime(cur_system_time, sizeof(cur_system_time), "%Y-%m-%d %T", &cur_tm); return cur_system_time; }