def datetime_to_iso8601(whendt):
    """
    Converts a datetime object to a date string of the ISO8601 with timezone.

    The format is of the form ``YYYY-MM-DDTHH:MM:SS.MS-TZ``, for example::

        2020-06-10T01:47:35.186550-06:00

    :param datetime whendt: Datetime object. *Any naive datetime object is
     considered a local timezone datetime.* To correctly pass a UTC datetime
     use::

        from datetime import datetime, timezone
        now = datetime.now(timezone.utc)

    :return: A string with the datetime in the ISO8601 with timezone format.
    :rtype: str
    """
    # Any naive datetime is a local timezone datetime
    if whendt.tzinfo is None:
        whendt = whendt.astimezone(tz=None)
    return whendt.isoformat()