time.h 格式化日期
time()获取当前日期的秒,localtime()获取当前时间字段, strftime格式化日期到字符串
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <pthread.h> #include <time.h> int main() { time_t rawtime; struct tm *timeInfo = NULL; char buff[80]; time(&rawtime); printf("rawtime:%d ", rawtime); timeInfo = localtime(&rawtime); strftime(buff, sizeof(buff),"%Y-%m-%d %H:%M:%S", timeInfo); printf("buff:%s ", buff); return 0; }