title: Retrieve Linux Time using struct timespec
body: <p>Can someone please suggest how can I retrieve linux time using </p>
  
  <blockquote>
    <p>struct timespec ts</p>
  </blockquote>
  
  <p>type? It just gives me time since Epoch. Can I get the actual Linux time using this datatype?</p>
  
  <p>Brief Background: I am writing a logger utility on embedded device with timestamp resolution in milli/micro seconds. The source adds timestamp which is consumed by destination component. </p>
  
  <pre><code>struct stLogItem logitem; //stLogItem has a member, struct timespec ts    
  clock_gettime(clk_id, &amp;logitem.ts);
  </code></pre>
  
  <p>The destination component is printing this log timestamp on file/console. But the date which is printed out is time since Epoch, and not the actual Linux date.</p>
  
  <blockquote>
    <p>The printed data is:
     1970-01-01 23:30:07.586864475</p>
  </blockquote>
  
  <p>Whereas, the Linux date is different as shown below:</p>
  
  <blockquote>
    <p>root@imh:# date</p>
    
    <p>Tue Nov 14 11:34:12 UTC 2017</p>
  </blockquote>
  
  <p>Its not a format issue. It is about getting the current Linux time (in nano seconds).</p>