0

I'm doing a C programming course at uni and one of the tasks is to create an OpenGL analogue clock on the screen. I want to drive the hour, minute, and second hands from the actual time.

How do I read the hour, minute, and seconds from system time? As integers would be best. I've had a look around and can't find anything quite like what I'm after.

Mike Doe
  • 16,349
  • 11
  • 65
  • 88
Billzilla
  • 9
  • 1

1 Answers1

0

You should use localtime, like this:

#include <time.h>

time_t timestamp = time(NULL);
if (timestamp != (time_t)-1) {
    struct tm *t = localtime(&timestamp);
    // Use t->tm_hour, t->tm_min and t->tm_sec, which are ints
}

See man 3 localtime for more info.

Samuel Peter
  • 4,136
  • 2
  • 34
  • 42