Merge pull request #89 from 5ooo/master

优化linux下elog_port_get_time函数
pull/91/head
朱天龙 (Armink) 5 years ago committed by GitHub
commit e1d38c3b74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -104,16 +104,14 @@ void elog_port_output_unlock(void) {
*/ */
const char *elog_port_get_time(void) { const char *elog_port_get_time(void) {
static char cur_system_time[24] = { 0 }; static char cur_system_time[24] = { 0 };
time_t timep;
struct tm *p; time_t cur_t;
struct tm cur_tm;
time(&timep);
p = localtime(&timep); time(&cur_t);
if (p == NULL) { localtime_r(&cur_t, &cur_tm);
return "";
} strftime(cur_system_time, sizeof(cur_system_time), "%Y-%m-%d %T", &cur_tm);
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);
return cur_system_time; return cur_system_time;
} }

Loading…
Cancel
Save