将日期格式Www-Mmm-dd hh:mm:ss yyyy转换为c++中的dd hh:mm:ss字符串

convert date format Www Mmm dd hh:mm:ss yyyy to dd hh:mm:ss string in c++

本文关键字:mm hh ss c++ 中的 dd 字符串 转换 格式 日期 yyyy      更新时间:2023-10-16

我想转换日期格式"Www-Mmm-dd hh:mm:ss-yyyy",并仅将"dd hh:mm:ss"复制到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] = ''; //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());