Convert string to datetime object.
483230
def convert_date(date):
    """"""
    date = convert_month(date, shorten=False)
    clean_string = convert_string(date)
    return datetime.strptime(clean_string, DATE_FMT.replace('-',''))
930820
def parse_datetime(value):
    """"""

    if isinstance(value, (string_types, text_type, binary_type)):
        value = dateutil.parser.parse(value)
        value.replace(tzinfo=dateutil.tz.tzutc())
        return value
    elif isinstance(value, datetime.datetime):
        value.replace(tzinfo=dateutil.tz.tzutc())
        return value
    elif isinstance(value, datetime.date):
        value = datetime.datetime(value.year, value.month, value.day)
        value.replace(tzinfo=dateutil.tz.tzutc())
        return value
    else:
        raise ValueError('Value must be parsable to datetime object. Got `{}`'.format(type(value)))
1101116
def parse(input):
    '''
    
    '''
    if isinstance(input, datetime):
        return input
    if isinstance(input, date):
        return date_to_datetime(input)
    if isinstance(input, time):
        return time_to_datetime(input)
    if isinstance(input, (int, float)):
        return timestamp_to_datetime(input)
    if isinstance(input, (str)):
        return string_to_data_time(input)
    return None
1339784
def datetime(self):
        """"""
        if not self._datetime_calculated:
            self._datetime_calculated = True

            # if no datetime after 10 tokens, break to avoid parsing
            # very long lines
            split_tokens = self.split_tokens[:10]

            for offs in range(len(split_tokens)):
                dt = self._match_datetime_pattern(split_tokens[offs:offs + 4])
                if dt:
                    self._datetime = dt
                    self._datetime_nextpos = offs
                    if self._datetime_format.startswith("iso8601"):
                        self._datetime_nextpos += 1
                    else:
                        self._datetime_nextpos += 4

                    # separate datetime str and linestr
                    self._line_str = (' '.join(self.split_tokens
                                               [self._datetime_nextpos:]))

                    if self.level:
                        self._datetime_nextpos += 2

                    self._reformat_timestamp(self._datetime_format)
                    break

        return self._datetime
685170
def TAF_datetime_to_datetime_object(
    datetime_string             = None,
    datetime_for_year_and_month = None  # e.g. datetime.datetime.utcnow()
    ):

    

    if datetime_string.endswith("24"):

        datetime_string = datetime_string[:-2] + "00"

        tmp = datetime.datetime.strptime(datetime_string, "%d%H") +\
              datetime.timedelta(days = 1)

    else:

        tmp = datetime.datetime.strptime(datetime_string, "%d%H")

    return datetime.datetime(
        datetime_for_year_and_month.year,
        datetime_for_year_and_month.month,
        tmp.day,
        tmp.hour,
        tmp.minute
    )
729715
public static DateTime fromStringWithSeconds( String dateTimeString ) {
        DateTime dt = withSecondsformatter.parseDateTime(dateTimeString);
        return dt;
    }
454122
def Date(value):
    """"""
    from datetime import datetime
    try:
        return datetime(*reversed([int(val) for val in value.split('/')]))
    except Exception as err:
        raise argparse.ArgumentTypeError("invalid date '%s'" % value)
1072499
def isostr_to_datetime(dt_str):
    
    if len(dt_str) <= 20:
        return datetime.datetime.strptime(dt_str, "%Y-%m-%dT%H:%M:%SZ")
    else:
        dt_str = dt_str.split(".")
        return isostr_to_datetime("%sZ" % dt_str[0])
1149233
def _get_date_time_format(dt_string):
    '''
    
    '''
    valid_formats = [
        '%I:%M:%S %p',
        '%I:%M %p',
        '%H:%M:%S',
        '%H:%M',
        '%Y-%m-%d',
        '%m-%d-%y',
        '%m-%d-%Y',
        '%m/%d/%y',
        '%m/%d/%Y',
        '%Y/%m/%d'
    ]
    for dt_format in valid_formats:
        try:
            datetime.strptime(dt_string, dt_format)
            return dt_format
        except ValueError:
            continue
    return False
861283
def _str_to_datetime(datestr):
    
    # try known string
    try:
        return DATE_STRINGS[str(datestr).lower()]()
    except KeyError:  # any other string
        pass

    # use maya
    try:
        import maya
        return maya.when(datestr).datetime()
    except ImportError:
        pass

    # use dateutil.parse
    with warnings.catch_warnings():
        # don't allow lazy passing of time-zones
        warnings.simplefilter("error", RuntimeWarning)
        try:
            return dateparser.parse(datestr)
        except RuntimeWarning:
            raise ValueError("Cannot parse date string with timezone "
                             "without maya, please install maya")
        except (ValueError, TypeError) as exc:  # improve error reporting
            exc.args = ("Cannot parse date string {0!r}: {1}".format(
                datestr, exc.args[0]),)
            raise
943282
def strptime(cls, date_string, format):
        ''
        import _strptime
        return _strptime._strptime_datetime(cls, date_string, format)
905237
def to_naive_datetime(self, value):
        
        if isinstance(value, (six.integer_types, float, six.string_types)):
            try:
                return self.from_number(value)
            except ValueError:
                return self.datetime_str_to_datetime(value)

        if isinstance(value, datetime.datetime):
            return value

        raise exceptions.ValidationError(
            "Unable to convert value: '%s' to python data type" % value,
            code="invalid_datetime"
        )
988125
def _parse_date(self, date_string):
        """"""
        date = datetime.strptime(date_string, self._DATE_FORMAT)
        self.date = self._TZ.localize(date).astimezone(pytz.UTC)
666490
def _read_date_from_string(str1):
    
    full_date = [int(x) for x in str1.split('/')]
    return datetime.date(full_date[0], full_date[1], full_date[2])
1111245
def datetime_from_ISO_string(s):
    
    try:
        return datetime.datetime.strptime(s, '%Y-%m-%dT%H:%M:%S')
    except ValueError:
        try:
            return datetime.datetime.strptime(s, '%Y-%m-%d')
        except ValueError:
            return datetime.datetime.strptime(s, '%Y-%m-%dT%H:%M:%S.%f')
1247575
def str_to_datetime(dt_str, fmt='%Y-%m-%d %H:%M:%S'):
    
    d_time = datetime.datetime.strptime(dt_str, fmt)
    return d_time
991736
def str_to_time(time_str: str) -> datetime.datetime:
    
    pieces: Any = [int(piece) for piece in time_str.split('-')]
    return datetime.datetime(*pieces)