преобразовать формат даты Www Mmm dd hh:mm:ss yyyy to dd hh:mm:ss строка в С++

я хочу преобразовать формат даты "Www Mmm dd hh:mm:ss yyyy" и скопировать только "dd hh:mm:ss" в строку на С++.
до сих пор я пытался это сделать:

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

person Tamir Hochman    schedule 04.12.2015    source источник
comment
Используйте std::string и substr?   -  person Some programmer dude    schedule 04.12.2015
comment
Или почему бы не использовать std::strftime, чтобы получить правильную строку с самого начала?   -  person Some programmer dude    schedule 04.12.2015
comment
привет, Иоахим Пилеборг, спасибо за ответ, но я никогда не использовал этот тип переменных, можете ли вы сделать что-то более простое? :)   -  person Tamir Hochman    schedule 04.12.2015


Ответы (1)


Код будет выглядеть, как показано ниже, как предложено Иоахимом с использованием substr

std::string temp = str.substr(11, 9); //from 11the place copy next 9 characters
strcpy(str1, temp.c_str());
person rahul.deshmukhpatil    schedule 04.12.2015
comment
благодарю вас !! :) небольшое исправление: std::string temp = str,substr(11, 9); //с 11-го места копируем следующие 9 символов strcpy(str1, temp.c_str()); - person Tamir Hochman; 04.12.2015