mirror of
https://github.com/armink/EasyLogger.git
synced 2025-01-31 13:32:52 +08:00
[demo][linux] optimize elog_port_get_time
This commit is contained in:
parent
bb20ae32f6
commit
0faf2f865e
@ -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(&timep);
|
time_t cur_t;
|
||||||
p = localtime(&timep);
|
struct tm cur_tm;
|
||||||
if (p == NULL) {
|
|
||||||
return "";
|
time(&cur_t);
|
||||||
}
|
localtime_r(&cur_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);
|
strftime(cur_system_time, sizeof(cur_system_time), "%Y-%m-%d %T", &cur_tm);
|
||||||
|
|
||||||
return cur_system_time;
|
return cur_system_time;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user