from datetime import datetime


def time_to_iso(dt: datetime) -> str:
    """
    Convert :py:class:`datetime <datetime.datetime>` object to ISO 8601 style formatted time.

    :param dt: :py:class:`datetime <datetime.datetime>` object as a time representation.
    :return: Text string containing ISO 8601 formatted time.
    """
    result = dt.isoformat()  # removed timespec="milliseconds" due to the python 3.5 does not support it
    if result.find(".") == -1:
        result += ".000"
    return result