title: Get current time in milliseconds, or HH:MM:SS:MMM format
body: <p>I've written a c++ function to get the current time in <code>HH:MM:SS</code> format. How can I add milliseconds or nanoseconds, so I can have a format like <code>HH:MM:SS:MMM</code>? If not possible, a function that returns current time in ms would also be good. I can then calculate the relative time distances between two log points myself.</p>
  
  <pre><code>string get_time()
  {
      time_t t = time(0);   // get time now
      struct tm * now = localtime(&amp;t);
      std::stringstream sstm;
      sstm &lt;&lt; (now-&gt;tm_hour) &lt;&lt; ':' &lt;&lt; (now-&gt;tm_min) &lt;&lt; ':' &lt;&lt; now-&gt;tm_sec;
      string s = sstm.str();
      return s;
  }
  </code></pre>