title: pysrt: get time in milliseconds
body: <p>I would like to get the start and  end time of a subtitle file in milliseconds:</p>
  <pre><code>SIMPLE_FILE = &quot;&quot;&quot;
  1
  00:00:03,010 --&gt; 00:00:33,400
  cette matrice-là &lt;i&gt;E&lt;sub&gt;t&lt;/sub&gt;·…·E&lt;sub&gt;1&lt;/sub&gt;A&lt;/i&gt; possède une ligne
  
  2
  00:01:00,000 --&gt; 00:02:31,020
  there was a SubRip file
  with two subtitles.
  &quot;&quot;&quot;
  with open(&quot;subtitles.srt&quot;, &quot;w&quot;, encoding=&quot;utf-8&quot;) as fp:fp.write(SIMPLE_FILE)
  </code></pre>
  <p>I load the subtitle file using <a href="https://github.com/byroot/pysrt" rel="nofollow noreferrer">pysrt</a>:</p>
  <pre><code>import pysrt
  sub = pysrt.open(&quot;subtitles.srt&quot;)
  # Start and End time
  start = sub[0].start.to_time()
  end = sub[0].end.to_time()
  
  print(start)
  print(end)
  </code></pre>
  <blockquote>
  <p>00:00:03.010000</p>
  <p>00:00:33.400000</p>
  </blockquote>
  <p>As you can see I am getting a Hour:Minutes:Seconds.Millisecond format back. Now, my question is: how can I convert this into milliseconds?</p>
  <h2>Edit</h2>
  <p>I checked the type:</p>
  <pre><code>type(start)
  </code></pre>
  <blockquote>
  <p>datetime.time</p>
  </blockquote>
  <h2>Edit 2</h2>
  <p>Based on <a href="https://stackoverflow.com/questions/52730311/converting-string-to-datetime-in-python-using-strptime">Converting string to datetime in Python using strptime</a></p>
  <p>I tried:</p>
  <pre><code>from datetime import datetime
  
  dt_obj = datetime.strptime(str(start),
                             '%H:%M:%S.%f')
  millisec = dt_obj.timestamp() * 1000
  
  print(millisec)
  </code></pre>
  <p>I get:</p>
  <blockquote>
  <hr />
  <p>OSError                                   Traceback (most recent call
  last)  in ()
  3 dt_obj = datetime.strptime(str(start),
  4                            '%H:%M:%S.%f')
  ----&gt; 5 millisec = dt_obj.timestamp() * 1000
  6
  7 print(millisec)</p>
  <p>OSError: [Errno 22] Invalid argument</p>
  </blockquote>