I been searching all over Google and nothing seems to be consistent/useful about timers.
Does anyone know how to get the current time? I want to be able to get the start time and another time and subtract them to get the difference or be able to run a loop for a certain time.
Current time, also known as system time or "wall time" can be adjusted by the user (or by the NTP client, or some other means) at any moment. It is not suitable for measuring intervals.
(but, for reference, it can be obtained with time(), system_clock::now(), or with various OS means, such as gettimeofday())
What is suitable for measuring duration of a loop is the monotonic time, time that can never be adjusted by the user, can never run faster or slower, and always increments at a steady rate. Such time can be obtained with clock(), steady_clock::now(), or with various OS means (clock_gettime() is a good one on Linux and QueryPerformanceCounter() on Windows).
Monotonic time has no meaning on its own, only the difference (value after loop minus value before loop) has a meaning.
I think he wants http://www.cplusplus.com/reference/clibrary/ctime/time
Yes, and no. They are from C, but are supported in C++, as are most things from C. Notice the <c...> prefix in the headers; like <cmath> and <cstdlib>. These are C++ headers for C constructs.
I read all those, but I really have not a clue which to use to capture the interval. My main goal is to run the a loop for lets say 15 seconds. I would need the current time start and then I would have to make a loop to check if the difference between the current time now and current time start is still less than or equal to 15 seconds. I prefer something that will give me seconds over like clock, which I am not sure if it gives like 10:10 or 10:10:10.
Like based on the descriptions, I wasn't sure which did what. I wanted to measure intervals in seconds, so I wanted to see which of those functions would allow me to do such. Wasn't sure if those gave me the actual time like the form of hh:mm or hh:mm:ss or something different.
time() measures ("real world") seconds. However, it's not in a nice format. I believe it returns a Unix time stamp (the number of seconds since 12:00 midnight UTC on January 1, 1970. http://en.wikipedia.org/wiki/Unix_time )
Since you need the measure of the difference in seconds between to times, it should work for you (even without it being a pretty number.)
time_t startTime = time();
//do stuff that takes awhile, at least a few seconds...
time_t endTime = time();
cout << "This is how long the program took: " << (endTime - startTime);
If you need to print something in a format, like HH:MM:SS, there are STL function for that I believe.
Okay, explain how you would do it if you wrote a time routine? Remember that a Unix Time Stamp is only 32 bits (4 bytes.) What I mean is, how would you define "the current time" unambiguously.