1. 程式人生 > >C/C++ 獲取當前系統時間到字串

C/C++ 獲取當前系統時間到字串

#include <time.h>
#include <stdlib.h>

char *pszCurrTime = (char*)malloc(sizeof(char)*20);
memset(pszCurrTime, 0, sizeof(char)*20);

time_t now;
 time(&now);
 strftime(pszCurrTime, 20 , "%Y/%m/%d %H:%M:%S", localtime(&now));

時間格式即為 2011/07/08 11:13:44