match = re.match('\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d+Z',
    date_string)
if match:
    return datetime.strptime(date_string, '%Y-%m-%dT%H:%M:%S.%fZ')
match = re.match('\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z', date_string)
if match:
    return datetime.strptime(date_string, '%Y-%m-%dT%H:%M:%SZ')
match = re.match('\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}Z', date_string)
if match:
    return datetime.strptime(date_string, '%Y-%m-%dT%H:%MZ')
return false
python strptime format with optional bits