uwp How to get current DateTime in C++ UWP GetCurrentDateTime()

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

#include <windows.h>

static Windows::Foundation::DateTime GetCurrentDateTime() {
    // Get the current system time
    SYSTEMTIME st;
    GetSystemTime(&st);

    // Convert it to something DateTime will understand
    FILETIME ft;
    SystemTimeToFileTime(&st, &ft);

    // Conversion to DateTime's long long is done vie ULARGE_INTEGER
    ULARGE_INTEGER ui;
    ui.LowPart = ft.dwLowDateTime;
    ui.HighPart = ft.dwHighDateTime;

    DateTime currentDateTime;
    currentDateTime.UniversalTime = ui.QuadPart;
    return currentDateTime;
}


Got any uwp Question?