|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h> |
|
|
|
|
|
#include <string.h> |
|
|
#include <time.h> |
|
|
#include <time.h> |
|
|
|
|
|
#include <sys/time.h> |
|
|
|
|
|
#include <assert.h> |
|
|
|
|
|
|
|
|
#include "../inc/lc6_time.h" |
|
|
#include "../inc/lc6_time.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
time_t lc6time_get(void) { |
|
|
time_t lc6time_get(void) { |
|
|
return time(NULL); |
|
|
return time(NULL); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
unsigned char *lc6time_getstr(void) { |
|
|
|
|
|
struct timeval tv; |
|
|
|
|
|
struct tm tm; |
|
|
|
|
|
unsigned char *str = malloc(sizeof("yyyy-MM-dd HH:mm:ss.SSS")+1); |
|
|
|
|
|
|
|
|
|
|
|
assert(str); |
|
|
|
|
|
gettimeofday(&tv, NULL); |
|
|
|
|
|
gmtime_r(&tv.tv_sec, &tm); |
|
|
|
|
|
|
|
|
|
|
|
sprintf((char*)str, "%04i:%02i:%02i %02i-%02i-%02i.%03li", |
|
|
|
|
|
tm.tm_year + 1900, |
|
|
|
|
|
tm.tm_mon + 1, |
|
|
|
|
|
tm.tm_mday, |
|
|
|
|
|
tm.tm_hour, |
|
|
|
|
|
tm.tm_min, |
|
|
|
|
|
tm.tm_sec, |
|
|
|
|
|
tv.tv_usec / 1000); |
|
|
|
|
|
|
|
|
|
|
|
return str; |
|
|
|
|
|
} |