getting current time
Aug 4, 2012 at 10:00am UTC
1 2 3 4 5
time_t currentTime;
struct tm * ptm = localtime(¤tTime);
std::cout << ptm->tm_hour << ":" << ptm->tm_min << ":" << ptm->tm_sec << std::endl;
}
output:
6:45:32
2:21:56
...
2:21:56
they are both wrong, in hours and minutes, but after the 6:45:32 (or whatever it decides to print out) it always prints 2:21:56, does anyone know how to get it working?
heh, never mind
1 2 3 4
time_t currentTime = time(0);
struct tm *ptm = localtime(¤tTime);
std::cout << ptm->tm_hour << ":" << ptm->tm_min << ":" << ptm->tm_sec << std::endl;
Last edited on Aug 4, 2012 at 10:03am UTC
Aug 4, 2012 at 10:02am UTC
I think you need to initialize currentTime first using the time() function.
Topic archived. No new replies allowed.