title: How can I create a Python timestamp with millisecond granularity?
body: <p>I need a single timestamp of milliseconds (ms) since epoch.  This should not be hard, I am sure I am just missing some method of <code>datetime</code> or something similar.</p>
  
  <p>Actually microsecond (µs) granularity is fine too. I just need sub 1/10th second timing.</p>
  
  <p>Example.  I have an event that happens every 750 ms, lets say it checks to see if a light is on or off.  I need to record each check and result and review it later so my log needs to look like this:</p>
  
  <pre class="lang-none prettyprint-override"><code>...00250 Light is on
  ...01000 Light is off
  ...01750 Light is on
  ...02500 Light is on
  </code></pre>
  
  <p>If I only have full second granularity my log would look like this:</p>
  
  <pre class="lang-none prettyprint-override"><code>...00 Light is on
  ...01 Light is off
  ...01 Light is on
  ...02 Light is on
  </code></pre>
  
  <p>Not accurate enough.</p>