def as_string(dt):
    """Format datetime instance `dt` according to RFC2822.

    >>> print (as_string (datetime.datetime (2001, 11, 8, 20, 8, 47)))
    08 Nov 2001 20:08:47 -0000
    """
    result = dt.strftime('%d %b %Y %H:%M:%S %z')
    if dt.utcoffset() is None:
        result += '-0000'
    return result
