一直对这个很迷糊,终于在unix高级编程看到了一个关系图。
这个图让人一目了然,结合实际经验,找出几个例子,彻底拿下它~
例子:
time_t now;
struct tm *data;
char time_buf[1024];
now = time(NULL);
data = localtime(&now);
memset(time_buf, 0, sizeof(time_buf));
snprintf(time_buf, sizeof(time_buf), "[%d]%d-%d-%d %d:%d:%d: ",
getpid(),
data->tm_year + 1900,
data->tm_mon + 1,
data->tm_mday,
data->tm_hour,
data->tm_min,
data->tm_sec);
//OR
strftime(time_buf, sizeof(time_buf), "%Y-%m-%d %H:%M:%S", data ) ;