M
M
Michael S.2021-10-24 20:23:17
Python
Michael S., 2021-10-24 20:23:17

Why doesn't the format fit?

try:
    obj = datetime.strptime('11.10.2021\xa0пн', '%d.%m.%Y\xa0%a')
    print(obj)
    print(obj.strftime("Date:%d Month:%m Year:%Y"))  # strftime to format datetime obj
except ValueError as ex:
    print("ValueError: ", ex)

Throws an error:
ValueError: time data '10/11/2021\xa0mon' does not match format '%d.%m.%Y\xa0%a'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dmshar, 2021-10-24
@BUUSSA

Because
either

obj = datetime.strptime('11.10.2021\xa0Mon', '%d.%m.%Y\xa0%a')

or
import locale
locale.setlocale(locale.LC_ALL, "ru")
obj = datetime.strptime('11.10.2021\xa0пн', '%d.%m.%Y\xa0%a')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question