def dh2hms(dh, format="{:02d}:{:02d}:{:06.3f}"):
    """Decimal hours as HH:MM:SS.SSS, or similar.

    Will work for degrees, too.

    Parameters
    ----------
    dh : float
    format : string, optional
      Use this format, e.g., for [+/-]HH:MM, use "{:+02d}:{:02d}".

    Returns
    -------
    hms : string

    """

    sign = -1 if dh < 0 else 1
    dh = abs(dh)
    hh = int(dh)
    mm = int((dh - hh) * 60.0)
    ss = ((dh - hh) * 60.0 - mm) * 60.0
    if ss >= 60:
        ss -= 60
        mm += 1
    if mm >= 60:
        mm -= 60
        hh += 1
    return format.format(sign * hh, mm, ss)