Hello i want to get my computer time using c++ i googled, but i couldnt find anything that suits me...

Time code should be able to use this function: if(hours == 10) { do something... }

Can you help me?
Thank you.

standard library time.h will do what you want. time() returns the current time in seconds since some pre-determined date (epoch), such as 1 Jan 1970. With that you can call localtime() or gmtime() to convert seconds into a structure that contains year, month, day, hour, and seconds.

I found those earlier, they seem to be 'C' and dont run with the rest of mine C++ program...

Sorry im not that smart to do it without example.
I tried this code and it worked! But it's C i cant make it to work with C++

#include <iostream>
#include <Windows.h>
#include <stdio.h>
#include <ctime>

int main()
{
while(1 < 2) {
SYSTEMTIME st;
GetSystemTime(&st);
st.wHour = st.wHour + 3;
printf("Hour:%d\nMinutes:%d\n" ,st.wHour,st.wMinute);
if (st.wMinute == 34 ) { blablabla }
system("cls");
}
     system("pause");
     }

Edited 5 Years Ago by evaldaskowka: n/a

But it's C i cant make it to work with C++

Be more specific. Why doesn't it work with C++? Are you getting compilation errors? Runtime errors?

How about you post the EXACT code you're trying. The code you posted here won't work for obvious reasons: blablabla

GetSystemTime() is an MS-Windows api function, not standard C or C++. If that is what you want to do then you don't need <ctime> header file.

This article has been dead for over six months. Start a new discussion instead.