【发布时间】:2015-12-04 08:48:36
【问题描述】:
我想将日期格式“Www Mmm dd hh:mm:ss yyyy”转换为 c++ 中的字符串。
到目前为止,我一直在尝试:
char str[255];
char str1[255];
int y = 0;
int i;
time_t timer;
timer = GetTickCount();
strcpy(str, ctime(&timer));
sendBuff[strlen(str) - 1] = '\0'; //to remove the new-line from the created string
//to copy from the string the exact Time Without Date from the struct of Www Mmm dd hh:mm:ss yyyy - will take only hh:mm:ss
for (i = 11; i < 19; i++, y++)
strcpy(&str1[y], &str[i]);
【问题讨论】:
-
或者为什么不使用
std::strftime从一开始就得到正确的字符串? -
嗨 Joachim Pileborg,谢谢你的回答,但我从来没有使用过这种类型的变量,你能做点更简单的吗? :)
标签: c++ string date datetime gettickcount