在C ++ / CX中解析JSON ISO8601日期 [英] Parse JSON ISO8601 date in C++/CX
问题描述
我有一个来自JSON2012-08-01T15:42:06Z的日期字符串,并希望在Windows运行时解析。据我所知,只有 COleDateTime 可以处理这个。
我只能得到它正确解析字符串,当我拿出'T'& 'Z'字符,但是在我的末尾添加了额外的解析步骤。
WORKS:
COleDateTime dateTime;
dateTime.ParseDateTime(L2012-08-01 15:42:06,0UL,1033UL);
FAILS:
COleDateTime dateTime;
dateTime.ParseDateTime(L2012-08-01T15:42:06Z,0UL,1033UL);任何人都有任何想法? 解决方案如果您的日期字符串格式一致,您可以使用 std :: get_time
将时间解析为 tm
struct,将相关位复制到 SYSTEMTIME
中,然后从中转换为 FILETIME
然后到 Windows :: Foundation :: DateTime
。
信息 std :: get_time
: http://en.cppreference.com/w / cpp / io / manip / get_time
从 SYSTEMTIME
转换为 DateTime
:如何解析Metro(C ++ / CX)应用程序中的日期?
I have a date string coming from JSON "2012-08-01T15:42:06Z" and want to parse that in Windows Runtime. As far as I know, only COleDateTime is available to handle this.
I can only get it to correctly parse the string when I take out the 'T' & 'Z' characters, but that adds an extra parsing step on my end.
WORKS:
COleDateTime dateTime;
dateTime.ParseDateTime(L"2012-08-01 15:42:06", 0UL, 1033UL);
FAILS:
COleDateTime dateTime;
dateTime.ParseDateTime(L"2012-08-01T15:42:06Z", 0UL, 1033UL);
Anyone have any idea?
解决方案 If your date string is formatted consistently, you can use std::get_time
to parse the time into a tm
struct, copy the relevant bits into a SYSTEMTIME
and from there convert to a FILETIME
and then to Windows::Foundation::DateTime
.
Info on std::get_time
: http://en.cppreference.com/w/cpp/io/manip/get_time
Code for converting from SYSTEMTIME
to DateTime
: How do I parse a date in a Metro (C++/CX) app?
这篇关于在C ++ / CX中解析JSON ISO8601日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!