from datetime import datetime


def str_to_date(dtstr):
    """
    Convert str to datetime

    Parameters
    ----------
    dtstr : str
        str to convert

    Returns
    -------
    datetime : datetime
        datetime
    """
    if len(dtstr) > 19 and dtstr[-3:-2] == ":":
        dtstr = dtstr[:-3] + dtstr[-2:]
    fmt = "%Y-%m-%dT%H:%M:%S"
    if "." in dtstr:
        fmt += ".%f"
    if dtstr[-5] == "+" or dtstr[-5] == "-":
        fmt += "%z"
    return datetime.strptime(dtstr, fmt)