This might be easy for most of you, but I am just starting so I need help. I need to get the Current System time and put it into a INT type variable for each of these 3 components (hour, minute, second)
Any help would be greatly appreciated
Thanks
Printable View
This might be easy for most of you, but I am just starting so I need help. I need to get the Current System time and put it into a INT type variable for each of these 3 components (hour, minute, second)
Any help would be greatly appreciated
Thanks
One way;
Code:#include <iostream>
#include <windows.h>
int main(void){
SYSTEMTIME st = {0};
GetSystemTime(&st);
int second = st.wSecond,
hour = st.wHour,
minute = st.wMinute;
std::cout << "Hour:Minute:Second" << std::endl;
std::cout << hour << ":" << minute << ":";
std::cout << second << std::endl;
}
Thanks dumah. the code helped me a lot.
If you don't care about portability and you only need to run this
on Windows systems, the code you have seen is fine. If you want
to take the code to other platforms, then you could use the
ANSI approach.
You can find some information on this at Microsoft's ANSI-CCode:#include <time.h> // for C
#include <ctime> // for C++
char currentTime[256];
time_t timeBuf;
struct tm* pTime;
time(&timeBuf);
pTime = localTime(&timeBuf);
sprintf(currentTime, "%02d/%02d%04d, %02d:%02d:%02d",
pTime->tm_mon+1, pTime->tm_mday,
(1900 + pTime->tm_year), pTime->tm_hour,
pTime->tm_min, pTime->tm_sec);
function page.
http://msdn.microsoft.com/library/de...nReference.asp
--Paul