Parse JSON ISO8601 date in C++/CX

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 16:36:04

问题


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?


回答1:


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?



来源:https://stackoverflow.com/questions/11768099/parse-json-iso8601-date-in-c-cx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!