title: How do I convert a std::chrono::time_point to long and back?
body: <p>I need to convert <code>std::chrono::time_point</code> to and from a <code>long</code> type (integer 64 bits). I´m starting working with <code>std::chrono</code> ...</p>
  
  <p>Here is my code:</p>
  
  <pre><code>int main ()
  {
       std::chrono::time_point&lt;std::chrono::system_clock&gt; now = std::chrono::system_clock::now();
  
      auto epoch = now.time_since_epoch();
      auto value = std::chrono::duration_cast&lt;std::chrono::milliseconds&gt;(epoch);
      long duration = value.count();
  
  
      std::chrono::duration&lt;long&gt; dur(duration);
  
      std::chrono::time_point&lt;std::chrono::system_clock&gt; dt(dur);
  
      if (dt != now)
          std::cout &lt;&lt; "Failure." &lt;&lt; std::endl;
      else
          std::cout &lt;&lt; "Success." &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>This code compiles, but does not show success.</p>
  
  <p>Why is <code>dt</code> different than <code>now</code> at the end?</p>
  
  <p>What is missing on that code?</p>