from datetime import datetime


def to_sec(ts):
    """Format time string to seconds.

    Args:
        ts (string): time string.

    Returns:
        time (float): second format
    """
    try:
        return datetime.strptime(ts, '%Y-%m-%d %H:%M:%S').timestamp()
    except:
        return datetime.strptime(ts, '%Y-%m-%d %H:%M:%S.%f').timestamp()