gpt4 book ai didi

c++ - 转换日期格式 Www Mmm dd hh :mm:ss yyyy to dd hh:mm:ss string in c++

转载 作者:太空宇宙 更新时间:2023-11-04 13:23:41 24 4
gpt4 key购买 nike

我想将日期格式“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]);

最佳答案

代码将如下所示,正如 Joachim 使用 substr 所建议的那样

std::string temp = str.substr(11, 9); //from 11the place copy next 9 characters
strcpy(str1, temp.c_str());

关于c++ - 转换日期格式 Www Mmm dd hh :mm:ss yyyy to dd hh:mm:ss string in c++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34084182/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com