#include <sys/time.h>
#include <unistd.h>
void print_time(void)
{
time_t curr_time;
time(&curr_time);
struct tm *ptm = localtime(&curr_time);
struct timeval tv;
gettimeofday(&tv, NULL);
printf("\033[31m[%04d-%02d-%02d %02d:%02d:%02d.%03d]\n",
ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec, tv.tv_usec/1000);
}
红色 -> 31m
黄色 -> 33m
绿色 -> 32m
恢复白色 -> 0m