How to use the function ShellExecuteW to get the current date and time using the Win32 API in C++

1 Answer

0 votes
#include <windows.h>
#include <iostream>

int main() {
    FILETIME ft;
    SYSTEMTIME st;

    GetSystemTimeAsFileTime(&ft);
    FileTimeToSystemTime(&ft, &st);

    std::cout
        << st.wYear << "-"
        << st.wMonth << "-"
        << st.wDay << " "
        << st.wHour << ":"
        << st.wMinute << ":"
        << st.wSecond << "\n";
}



/*
run:

2026-1-24 17:23:25

*/

 



answered Jan 24 by avibootz
...