def formatTime(time, ampm):
    """
    Format time from 6:02PM to 18:02 (or 10:02PM to 22:02).

    Parameters
    ----------
    time : str
        Time formated as "6:02:24" (or 10:02:24)
    ampm : str
        Formatted as "A" or "P" for AM or PM

    Returns
    -------
    newtime : str
        Time formatted as "18:02:24" (or 22:02:24)

    """
    hour, minute, second = time.split(":")
    if ampm[0] == "P" and int(hour) < 12:
        newtime = str((int(hour) + 12) % 24) + ":" + minute + ":" + second
    else:
        newtime = time
    return newtime