I want to parse dates like these into a datetime object:
The following will work for the first d
If you want to use arbitrary wildcards, you can use datetime-glob, a module we developed to parse date/times from a list of files generated by a consistent date/time formatting. From the module's documentation:
>>> import datetime_glob
>>> matcher = datetime_glob.Matcher(
pattern='/some/path/*%Y-%m-%dT%H-%M-%SZ.jpg')
>>> matcher.match(path='/some/path/some-text2016-07-03T21-22-23Z.jpg')
datetime_glob.Match(year = 2016, month = 7, day = 3,
hour = 21, minute = 22, second = 23, microsecond = None)
>>> match.as_datetime()
datetime.datetime(2016, 7, 3, 21, 22, 23)