First of all I am relatively new to programming, and I need to know how to access the system's time, in hour, minute, second, and so on. Please help me with this... I think I need to #include
<time.h>, or is it <sys\time.h>, or am I way off base?
Printable View
First of all I am relatively new to programming, and I need to know how to access the system's time, in hour, minute, second, and so on. Please help me with this... I think I need to #include
<time.h>, or is it <sys\time.h>, or am I way off base?
<ctime> (or time.h if you will) would be where to go, yes.
Then check this site out. It has a list of the functions and how to use them:
http://www.cplusplus.com/ref/ctime/
Thankyou, however I'm not sure that's what I'm looking for. I went to the site, but
That would require complex math to convert the number of seconds since midnight,
Jan 1, 1970 into current hour, minute, and second. I would appreciate any further help
on the subject.
An example
Code:#include <ctime>
#include <iostream>
using namespace std;
int main()
{
time_t example;
struct tm * part2;
time(&example);
part2 = localtime( &example );
cout << part2->tm_hour << "\n"; //example of displaying single part of the time
cout << asctime(part2); //displaying all of the time
}
Thanks, I think this is all I needed... ;)
You gotta look at all the functions in <ctime> before you decide they don't work. That site has good examples, as well.
I did look at everything that seemed useful. I wanted to access hour, minute, and second
individually, not all at once or in a string or have to convert ten billion seconds into
minutes or hours, or any other nonsense. Which example did you think would work for
what I sought? Tell me and I'll check it out. Thanks...