from datetime import datetime


def time_format_matches(time_str, format):
    """Returns true if time_str is in provided strptime format."""
    try:
        if time_str != datetime.strptime(time_str, format).strftime(format):
            raise ValueError
        return True
    except ValueError:
        return False