C++ 转换C+中的字符串日期时间+;

C++ 转换C+中的字符串日期时间+;,c++,string,date,time,C++,String,Date,Time,我有一个以字符串形式表示的日期,格式为“2012-10-28”,我想将其转换为字符串格式“28/10/2012”。在C++的VisualStudio中,这可能是使用预定义函数吗?< p>不幸的是Windows中不存在。请在此寻求帮助: 然后,您可以使用windows中不存在的。写入日期。请在此寻求帮助: 然后,您可以使用书写日期。请查看 如果您不想使用COleDateTime,则ParseDateTime的实现只是一个简单的包装。请查看 如果您不想使用COleDateTime,则ParseDat

我有一个以字符串形式表示的日期,格式为“2012-10-28”,我想将其转换为字符串格式“28/10/2012”。在C++的VisualStudio中,这可能是使用预定义函数吗?

< p>不幸的是Windows中不存在。请在此寻求帮助:

然后,您可以使用windows中不存在的。

写入日期。请在此寻求帮助:

然后,您可以使用书写日期。

请查看

如果您不想使用COleDateTime,则ParseDateTime的实现只是一个简单的包装。

请查看


如果您不想使用COleDateTime,则ParseDateTime的实现只是一个简单的包装。

我就是这样解决的:

 Use sscan_f to break date into year, month and day.
 Create struct tm with the data above.
 Use strftime to convert from tm to string with the desired format.

我是这样想的:

 Use sscan_f to break date into year, month and day.
 Create struct tm with the data above.
 Use strftime to convert from tm to string with the desired format.
这可以做到:

#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

string format_date(string s)
{
    char buf[11];
    int a, b, c;
    sscanf(s.c_str(), "%d-%d-%d", &a, &b, &c);
    sprintf(buf, "%02d/%02d/%d", c, b, a);
    return buf;
}

int main()
{
    cout << format_date("2012-09-28") << endl;
}
#包括
#包括
#包括
使用名称空间std;
字符串格式\u日期(字符串s)
{
char-buf[11];
INTA、b、c;
sscanf(s.c_str(),%d-%d-%d“,&a,&b,&c);
sprintf(buf,“%02d/%02d/%d”,c,b,a);
返回buf;
}
int main()
{
cout这样就可以了:

#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

string format_date(string s)
{
    char buf[11];
    int a, b, c;
    sscanf(s.c_str(), "%d-%d-%d", &a, &b, &c);
    sprintf(buf, "%02d/%02d/%d", c, b, a);
    return buf;
}

int main()
{
    cout << format_date("2012-09-28") << endl;
}
#包括
#包括
#包括
使用名称空间std;
字符串格式\u日期(字符串s)
{
char-buf[11];
INTA、b、c;
sscanf(s.c_str(),%d-%d-%d“,&a,&b,&c);
sprintf(buf,“%02d/%02d/%d”,c,b,a);
返回buf;
}
int main()
{
Qt中的cout(一些嵌入式系统还不支持新的计时器类,所以在这里)
我在这里只是给出了如何转换字符串的想法,而不需要太多的混乱。
timer类无论如何都有epoch函数


QString从第二纪元(第64纪元)
{
qtexts;
时间\u t结果=历元;//标准::时间(空);
//Qt中的std::cout(一些嵌入式系统还不支持新的计时器类,所以在这里)
我在这里只是给出了如何转换字符串的想法,而不需要太多的混乱。
timer类无论如何都有epoch函数


QString从第二纪元(第64纪元)
{
qtexts;
时间\u t结果=历元;//标准::时间(空);

//std::您是说将字符串中的所有“-”替换为“/”,还是需要一些时间函数来完成此操作?您是说将字符串中的所有“-”替换为“/”,还是需要一些时间函数来完成此操作?