您的位置:首页 > 编程语言 > C语言/C++

c++ 时间戳、日期格式、字符串

2013-08-01 10:40 1881 查看
include<time.h>

time_t t;

t=time(0);//或者 time(&t);

time_t实际一般就是__int64,为时间戳

char now[64];

struct tm *ttime;

ttime = localtime(&t);

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);

更多参考:
/article/4695916.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: