import time
from datetime import datetime


def get_timestamp(fraction=True):
    """Return the current date and time formatted for a message header."""

    (year, month, day, hh, mm, ss, wd, y, z) = time.gmtime()
    d = datetime.utcnow()
    if fraction:
        s = "%04d%02d%02dT%02d%02d%02d.%dZ" % (
            d.year,
            d.month,
            d.day,
            d.hour,
            d.minute,
            d.second,
            d.microsecond,
        )
    else:
        s = "%04d%02d%02dT%02d%02d%02dZ" % (
            d.year,
            d.month,
            d.day,
            d.hour,
            d.minute,
            d.second,
        )
    return s