def datetime_to_str(dt):
    """Coverts a datetime into a timezone aware string.
    """
    r = dt.isoformat()
    if dt.microsecond:
        r = r[:23] + r[26:]
    if r.endswith('+00:00'):
        r = r[:-6] + 'Z'
    return r
