def str_to_sec(time_str):
    """Convert string to seconds.

    :param str time_str: time in string format
    :returns: seconds
    :rtype: float
    """
    time_str = time_str.split(".")
    sec = sum(x * int(t) for x, t in zip([1, 60, 3600], reversed(time_str[0].split(":"))))
    msec = int(time_str[1])/1000 if len(time_str) > 1 else 0.0
    return sec + msec