title: strptime, format and saving the milliseconds
body: <p>My gps, via gpsd, spits back a time in the format</p>
  
  <p><code>time_string = '1582-10-04T12:34:56.000Z'</code></p>
  
  <p>I can turn this string into a timezone aware <code>datetime</code> object
  with</p>
  
  <pre><code>from datetime import datetime, timedelta, timezone
  timeformat = '%Y-%m-%dT%H:%M:%S.000Z'  # ISO8601
  datetime.strptime(time_string, timeformat).replace(tzinfo=(timezone(timedelta(0))))  
  </code></pre>
  
  <p>...which is cool.  I can than manipulate the object, add, subtract, change timezones, calculate a time delta inclusive of a time zone change, etc..</p>
  
  <p>The problem is occasionally some aspect of the application will return a time string with milliseconds attached. </p>
  
  <p><code>time_string = '1582-10-04T12:34:56.123Z'</code></p>
  
  <p>...and all hell breaks loose.</p>
  
  <p><code>.strip('Z')</code> doesn't do it.</p>
  
  <p><code>timeformat = '%Y-%m-%dT%H:%M:%S</code> &lt;--without <code>.000</code> or <code>.000Z</code>
  does not work either as neither <code>b.strip('.000Z')</code> or permutations thereof.</p>
  
  <p>I can't seem to find an elegant way to save the millisecond(s), if, and when, they occur, and parse the string into a time zone aware datetime object. </p>