簡體   English   中英

在C ++中將日期格式Www Mmm dd hh:mm:ss yyyy轉換為dd hh:mm:ss字符串

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

我想轉換日期格式“ 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] = '\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());

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM