title: How to extract hours from time_t?
body: <p>I want to extract hours, minutes and seconds as integer values from a time_t value representing seconds since epoch.</p>
  
  <p>The value for hours is not correct. Why? </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;time.h&gt;
  
  #include &lt;unistd.h&gt;
  
  int main()
  {
      char buf[64];
  
      while (1) {
          time_t t = time(NULL);
          struct tm *tmp = gmtime(&amp;t);
  
          int h = (t / 360) % 24;  /* ### My problem. */
          int m = (t / 60) % 60;
          int s = t % 60;
  
          printf("%02d:%02d:%02d\n", h, m, s);
  
          /* For reference, extracts the correct values. */
          strftime(buf, sizeof(buf), "%H:%M:%S\n", tmp);
          puts(buf);
          sleep(1);
      }
  }
  </code></pre>
  
  <p>Output (the hour should be 10)</p>
  
  <pre><code>06:15:35
  10:15:35
  
  06:15:36
  10:15:36
  
  06:15:37
  10:15:37
  </code></pre>