分析C++/CX中的JSON ISO8601日期

Parse JSON ISO8601 date in C++/CX

本文关键字:JSON ISO8601 日期 中的 CX C++ 分析      更新时间:2023-10-16

我有一个来自JSON"2012-08-01T15:42:06Z"的日期字符串,希望在Windows Runtime中解析它。据我所知,只有COleDateTime可用于处理此问题。

只有当我去掉"T"&ampZ'字符,但这为我的端添加了额外的解析步骤。

作品:

COleDateTime dateTime;
dateTime.ParseDateTime(L"2012-08-01 15:42:06", 0UL, 1033UL);

失败:

COleDateTime dateTime;
dateTime.ParseDateTime(L"2012-08-01T15:42:06Z", 0UL, 1033UL);

有人知道吗?

如果您的日期字符串格式一致,您可以使用std::get_time将时间解析到tm结构中,将相关位复制到SYSTEMTIME中,然后从那里转换为FILETIME,然后转换为Windows::Foundation::DateTime

std::get_time信息:http://en.cppreference.com/w/cpp/io/manip/get_time

SYSTEMTIME转换为DateTime的代码:如何在Metro(C++/CX)应用程序中解析日期?