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
本文介绍如何使用C++标准库中的time.h进行时间处理,包括获取当前时间戳、将时间戳转换为可读字符串以及使用ctime函数转换时间。通过示例代码展示了如何实现这些功能。
5266

被折叠的 条评论
为什么被折叠?



