code: def _datetime_to_millis(dtm):
      
      if dtm.utcoffset() is not None:
          dtm = dtm - dtm.utcoffset()
      return int(calendar.timegm(dtm.timetuple()) * 1000 +
                 dtm.microsecond // 1000)
docs: Convert datetime to milliseconds since epoch UTC.