getting current time

1
2
3
4
5
    time_t currentTime;

    struct tm * ptm = localtime(&currentTime);
    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(&currentTime);
    std::cout << ptm->tm_hour << ":" << ptm->tm_min << ":" << ptm->tm_sec << std::endl;
Last edited on
I think you need to initialize currentTime first using the time() function.
Topic archived. No new replies allowed.