title: Number of seconds since midnight
body: <p>I wrote the below code to get the number of seconds since midnight.</p>
  
  <p>However, I'm not great with the C time date structs. Is there a simpler way of doing this using a standard C++ library?</p>
  
  <pre><code>// Get today's date
  time_t aTime = time(NULL);
  
  // Set the time to midnight
  struct tm* tm = localtime(&amp;aTime);
  tm-&gt;tm_sec = 0;
  tm-&gt;tm_min = 0;
  tm-&gt;tm_hour = 0;
  tm-&gt;tm_isdst = -1;
  time_t midnight = mktime(tm);
  
  // Create object representing now
  struct timespec now;
  clock_gettime(CLOCK_REALTIME, &amp;now);
  
  // Number of seconds (now) since Epoch
  const uint64_t nowSecsSinceEpoch = now.tv_sec;
  
  // Number of seconds (now) since midnight = seconds (now) since Epoch minus seconds (at midnight) since Epoch
  const uint64_t nowSecsSinceMidnight = nowSecsSinceEpoch - midnight;
  </code></pre>