code: def datetime_to_millis(x):
      
      if x is None:
          return None
      if hasattr(x, 'timestamp'):
          # Python >= 3.3
          secs = x.timestamp()
      elif x.tzinfo is None:
          # Timezone naive
          secs = (time.mktime((x.year, x.month, x.day,
                               x.hour, x.minute, x.second,
                               -1, -1, -1)) + x.microsecond / 1e6)
      else:
          # Timezone aware
          secs = (x - _EPOCH).total_seconds()
      return int(secs * 1000)
docs: Convert a `datetime.datetime` to milliseconds since the epoch