I have a C++/CX app that is processing some data from a file. It has a string in there representing the culture that was used to save the dates, and it has some dates. I need to convert them from strings to Platform::DateTime. I have heard that Windows::Globalization::DateTimeFormatting is the class to use, but I don’t see how to use it for that. Does anyone have an example?
Share
The C++/CX projection of WinRT differs from the Managed (C#/VB) projection in a number of ways, and one of the most major is in the projection of fundamental types (such as
Point,Size,String, andDateTime).The managed projection projects these types as .NET types (with all the underlying support of the BCL) while the C++ projection generally minimally projects these types for interop, expecting the user to rely on C++ library support for more advanced functionality.
So, where in .NET a signed 32-bit integer becomes a
System.Int32(with its relevant.Parsefunctionality) in C++ you get a regular C++intand are expected to use CRT functionality (_wtoi) to accomplish a similar task. This difference often results in a ‘feature gap’ between the different projections, one of the more painful of which is in dealing with theDateTimestructure (which has very rich support in the BCL).The solution I’ve managed to get was to start with the
COleDateTimeclass (found by including ATLComTime.h) and goingCOleDateTime->SYSTEMTIME->FILETIME->_ULARGE_INTEGER->Windows::Foundation::DateTime. It’s serious gymnastics, but theCOleDateTimeclass has the language-specific parsing capability that you require.I’ve asked around about the
DateTimeFormatterclass, and the documentation is incorrect; it does not support parsing and is not intended to (only formatting).