gpt4 book ai didi

c++ - 如何将 std::string (YYYY-MM-DD) 解析为 COleDateTime 对象?

转载 作者:行者123 更新时间:2023-12-03 08:04:26 24 4
gpt4 key购买 nike

我有一个 COleDateTime 对象,我想解析 YYYY-MM-DD 格式的日期字符串。

例如,字符串变量是:

std::string strDate = "2022-07-04";

COleDateTime 允许我使用 ParseDateTime 解析字符串,但我看不出有什么方法可以告诉它日期字符串的组成部分是什么格式。在 C# 中,我可以使用 DateTime.Parse... 来做到这一点。

最佳答案

为什么不只是一个简单的格式化输入。

std::stringstream ss(strDate);
int year, month, day;
char dash;
ss >> year >> dash >> month >> dash >> day;
COleDateTime(year, month, day, 0, 0, 0);

关于c++ - 如何将 std::string (YYYY-MM-DD) 解析为 COleDateTime 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72856018/

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