title: Any difference between clock_gettime( CLOCK_REALTIME .... ) and time()?
body: <p>A simple question: do <code>time(...)</code> and <code>clock_gettime( CLOCK_REALTIME, ... )</code> produce the same time theoretically (in respect to seconds only)?</p>
  
  <hr>
  
  <p>Here's what I mean:</p>
  
  <pre><code>time_t epoch;
  time( &amp;epoch );
  </code></pre>
  
  <p>and</p>
  
  <pre><code>struct timespec spec;
  clock_gettime( CLOCK_REALTIME, &amp;spec );
  </code></pre>
  
  <p>Are these two supposed to return exactly the same result (in respect to seconds)? </p>
  
  <p>I "tested" this with changing time and time zones and <code>epoch</code> and <code>spec.tv_sec</code> always show the same result, but the documentation of <code>CLOCK_REATIME</code> confuses me a bit and I'm not sure, that they will always be the same. </p>
  
  <hr>
  
  <p>Real world situation: I have a piece of code, which uses <code>time</code>. Now I want to have the time in milliseconds (which can be taken from <code>spec.tv_nsec</code>, multiplied by 1000000). So I think about removing <code>time</code> and using directly <code>clock_gettime</code>, but I'm not sure if this will remain the same in all situations.</p>
  
  <hr>
  
  <p><sub>The question is somehow related to <a href="https://stackoverflow.com/questions/12392278/measure-time-in-linux-time-vs-clock-vs-getrusage-vs-clock-gettime-vs-gettimeof">Measure time in Linux - time vs clock vs getrusage vs clock_gettime vs gettimeofday vs timespec_get?</a> but the information there was not enough for me.. I think.</sub></p>