如何将STD :: String(Yyyy-MM-DD)放入coledateTime对象?
我有一个coleDateTime
对象,我想用格式yyyy-mm-dd
来解析一个日期字符串。
例如,字符串变量是:
std::string strDate = "2022-07-04";
coledateTime
允许我使用parsedateetime
来解析字符串,但是我看不到它告诉它日期字符串的组件是什么格式是。在C#中,我可以使用dateTime.parse ...
来做。
I have a COleDateTime
object and I want to parse a date string in the format YYYY-MM-DD
.
The string variable, for example, is:
std::string strDate = "2022-07-04";
COleDateTime
allows me to use ParseDateTime
to parse a string, but I see no way to tell it what format the components of the date string are. In C# I can do such with DateTime.Parse...
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为什么不只是简单的格式输入。
Why not just a simple formatted input.
根据@xmri的建议,我决定使用的评论:
Based on the suggestion by @xMRi in the comments I have decided to use:
coledateTime :: parseDateTime
使用默认参数lang_user_default
,它可以称为或
“ 2022-07-07-04”
使用长期格式要安全,因为很明显,这一年就在开始,预计每月将在中间。我相信任何LCID都应返回2022- 7月4日
(我是60%肯定!)如果日期字符串很短,它可能会与
mm/dd/yy 混淆。格式,但这不是问题。
要手动制作
LCID
,请参见下面的英语示例,尽管在这种情况下不需要。COleDateTime::ParseDateTime
uses default parameterLANG_USER_DEFAULT
, it can be called asOr
"2022-07-04"
uses long date format so it should be safe, because it is clear that the year is at the start, and month is expected to be in the middle. I believe any LCID should return2022-July-4th
(I am 60% sure!)If the date string was short, it could get confused with
MM/DD/YY
format, but that's not a problem here.To make the
lcid
manually, see the English-US example below, although it should not be necessary in this case.