|
用C的函数取就可以了。
贴个例子给你看看,这是我写日志的函数:
time_t now;
struct tm timenow;
char content[2048];
time(&now);
timenow = *(localtime(&now));
// printf("time is: [%d-%02d-%02d %02d:%02d:%02d ]", timenow.tm_year+1900,timenow.tm_mon+1,timenow.tm_mday, timenow.tm_hour, timenow.tm_min, timenow.tm_sec);
sprintf(content, "[%d-%02d-%02d %02d:%02d:%02d] %s", timenow.tm_year+1900,timenow.tm_mon+1,timenow.tm_mday, timenow.tm_hour, timenow.tm_min, timenow.tm_sec, logBody);
if (log_flag != 0)
printf(content);
fprintf(pLog, content); |
|