jueves, 3 de septiembre de 2015

Windows Runtime DateTime to SYSTEMTIME conversion

This post is about how to make date/time conversion between Windows::Foundation::DateTime and SYSTEMTIME structure types. Let's go to see by example:

// First we obtain the current DateTime from Calendar class

Windows::Globalization::Calendar^ cal = ref new Windows::Globalization::Calendar();
Windows::Foundation::DateTime date= cal->GetDateTime();

// Here, we are converting DateTime to a 64bit value (UniversalTime format)
time.QuadPart = date.UniversalTime;

// Now convert the ULARGE_INTEGER to a FILETIME structure
FILETIME fileTime;
fileTime.dwHighDateTime = time.HighPart;
fileTime.dwLowDateTime = time.LowPart;

// And finally we get a SYSTEMTIME value by calling the FileTimeToSystemTime Windows Api.
SYSTEMTIME systemTime;
FileTimeToSystemTime(&fileTime, &systemTime);

With C++ and once again, we are doing many things to something simple but sometimes necessary.

No hay comentarios:

Publicar un comentario