def format_datetime(date):
    """
    Convert datetime to UTC ISO 8601
    """
    # todo: test me
    if date.utcoffset() is None:
        return date.isoformat() + 'Z'

    utc_offset_sec = date.utcoffset()
    utc_date = date - utc_offset_sec
    utc_date_without_offset = utc_date.replace(tzinfo=None)
    return utc_date_without_offset.isoformat() + 'Z'
def format_datetime ( date ) : if date . utcoffset ( ) is None : return date . isoformat ( ) + 'Z' utc_offset_sec = date . utcoffset ( ) utc_date = date - utc_offset_sec utc_date_without_offset = utc_date . replace ( tzinfo = None ) return utc_date_without_offset . isoformat ( ) + 'Z'
Convert datetime to UTC ISO 8601