title: get gps time using gpsd/libgps C
body: <p>I'm trying to read data from a Adafruit ultimate gps using libgps.  I've found a code example that gives me all the information I need except gps time.  How can I grab the gps time that the gps sent over the serial port preferably in hours/minutes/seconds?</p>
  
  <p>I tried <code>gps_data.fix.time</code> but I'm not sure if that is system time or gps time.  </p>
  
  <pre><code>#include &lt;gps.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;math.h&gt;
  
  int main() {
      int rc;
      struct timeval tv;
  
      struct gps_data_t gps_data;
      if ((rc = gps_open("localhost", "2947", &amp;gps_data)) == -1) {
          printf("code: %d, reason: %s\n", rc, gps_errstr(rc));
          return EXIT_FAILURE;
      }
      gps_stream(&amp;gps_data, WATCH_ENABLE | WATCH_JSON, NULL);
  
      while (1) {
          /* time to wait to receive data */
          if (gps_waiting (&amp;gps_data, 500000)) {
          /* read data */
          if ((rc = gps_read(&amp;gps_data)) == -1) {
              printf("error occured reading gps data. code: %d, reason: %s\n", rc, gps_errstr(rc));
          } else {
              /* Display data from the GPS receiver. */
              if ((gps_data.status == STATUS_FIX) &amp;&amp; 
                  (gps_data.fix.mode == MODE_2D || gps_data.fix.mode == MODE_3D) &amp;&amp;
                  !isnan(gps_data.fix.latitude) &amp;&amp; 
                  !isnan(gps_data.fix.longitude)) {
                      gettimeofday(&amp;tv, NULL);
                  //*****************WOULD LIKE TO PRINT THE TIME HERE.*****************************
                      printf("height: %f, latitude: %f, longitude: %f, speed: %f, timestamp: %f\n", gps_data.fix.altitude, gps_data.fix.latitude, gps_data.fix.longitude, gps_data.fix.speed, gps_data.fix.time/*tv.tv_sec*/);
              } else {
                  printf("no GPS data available\n");
              }
          }
      }
  
      //sleep(1);
  }
  
  /* When you are done... */
  gps_stream(&amp;gps_data, WATCH_DISABLE, NULL);
  gps_close (&amp;gps_data);
  
  return EXIT_SUCCESS;
  </code></pre>
  
  <p>}</p>