import _datetime


def datetime_to_string(d):
    """Return the passed datetime encoded to a string. This will be a
    standard iso-formatted time in the UTC timezone (converting
    to UTC if the passed datetime is for another timezone)

    Args:
         d (datetime): Datetime to convert to string
    Returns:
         str: Datetime as a string

    """
    if d.tzinfo is None:
        d = d.replace(tzinfo=_datetime.timezone.utc)
    else:
        d = d.astimezone(_datetime.timezone.utc)

    # the datetime is in UTC, so write out the string without
    # the unnecessary +00:00
    return d.replace(tzinfo=None).isoformat()