Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,971 questions

51,913 answers

573 users

How to get the current system and date time in C++ Win32 API

1 Answer

0 votes
#include <Windows.h> 
#include <sstream>

int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
    // Get the current system time
    SYSTEMTIME systemTime;
    GetSystemTime(&systemTime);

    std::ostringstream oss;

    oss << systemTime.wDay << "/" << systemTime.wMonth << "/" << systemTime.wYear;
    oss << " ";
    oss << systemTime.wHour << ":" << systemTime.wMinute << ":" << systemTime.wSecond;

    std::string sysTime = oss.str();

    /*
    typedef struct _SYSTEMTIME {
        WORD wYear;
        WORD wMonth;
        WORD wDayOfWeek;
        WORD wDay;
        WORD wHour;
        WORD wMinute;
        WORD wSecond;
        WORD wMilliseconds;
    } SYSTEMTIME, *PSYSTEMTIME, *LPSYSTEMTIME;
    */

    MessageBoxA(0, sysTime.c_str(), "Current System Time", MB_OK);

    return 0;
}



/*
run:

7/12/2024 11:46:21

*/

 



answered Dec 7, 2024 by avibootz
...