from typing import Callable
from datetime import datetime


def parse_time(string: str, parser: Callable = datetime.strptime)->datetime:
    """
    :param string: date and time as a string
    :param parser: function to convert string to datetime
    :return: datetime.datetime
    """
    date_formats = ["%Y-%m-%dT%H:%M:%S.%fZ",
                    '%Y-%m-%dT%H:%M:%SZ']
    for df in date_formats:
        try:
            return parser(string, df)
        except ValueError:
            pass
    raise ValueError('Invalid time format in string %s' % string)