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?
相关问题
- Inheritance impossible in Windows Runtime Componen
- convert string to DateTime in C# with EDT at the e
- Jackson to deserialize Joda LocalDate from ISO Dat
- SQL - Convert Time Series Events into On/Off Pairs
- @DateTimeFormat in Spring produces off-by-one day
相关文章
- How to truncate seconds in TSQL?
- Working with hmacsha256 in windows store app
- How to remove seconds from datetime?
- OLS with pandas: datetime index as predictor
- Show flyout using BottomAppBar
- Calculate number of working days in a month [dupli
- How can I convert a OLE Automation Date value to a
- Out of bounds nanosecond timestamp
Would
std::get_time
do the trick? The example at the bottom of the page suggests you can parse a date string using a locale into atm
struct. I imagine you could then convert thetm
struct into the correct WinRTDateTime
.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.Parse
functionality) in C++ you get a regular C++int
and 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 theDateTime
structure (which has very rich support in the BCL).The solution I've managed to get was to start with the
COleDateTime
class (found by including ATLComTime.h) and goingCOleDateTime
->SYSTEMTIME
->FILETIME
->_ULARGE_INTEGER
->Windows::Foundation::DateTime
. It's serious gymnastics, but theCOleDateTime
class has the language-specific parsing capability that you require.I've asked around about the
DateTimeFormatter
class, and the documentation is incorrect; it does not support parsing and is not intended to (only formatting).I use this code:
auto cal = ref new Windows::Globalization::Calendar(); cal->AddSeconds(additionalSeconds); return cal->GetDateTime();
With Windows::Globalization::Calendar, you have all the nice time functions you need: https://msdn.microsoft.com/library/windows/apps/br206724