刚开始搞安卓的时候,并不知道logcat可以直接打印一个时间,然后自己傻傻的写了一个时间的函数 ,这里记录一下。
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
#include <string.h>
int main(int argc ,char *argv[])
{
char buf[32] = {0};
struct timeval tv;
struct tm tm;
size_t len = 28;
memset(&tv, 0, sizeof(tv));
memset(&tm, 0, sizeof(tm));
gettimeofday(&tv, NULL);
localtime_r(&tv.tv_sec, &tm);
strftime(buf, len, "%Y-%m-%d %H:%M:%S", &tm);
len = strlen(buf);
sprintf(buf + len, ".%-6.3d", (int)(tv.tv_usec/1000));
printf("%s\n", buf);
return 0;
}