include<time.h>
time_t t;
time_t t;
t=time(0);//或者 time(&t);
time_t实际一般就是__int64,为时间戳
char now[64];
struct tm *ttime;
struct tm *ttime;
ttime = localtime(&t);
strftime(now,64,"%Y-%m-%d %H:%M:%S",ttime);
strftime(now,64,"%Y-%m-%d %H:%M:%S",ttime);
cout << "the time is " << now << endl;
转换为字符串 : the time is 2008-05-30 15:29:59
char * ctime(const time_t *timer); //
char *str_time = ctime(&t); // 转换成日历类型,包含星期几等信息
printf("str_time = %s\n", str_time);
更多参考:
http://www.cnblogs.com/Wiseman/archive/2005/10/24/260576.html