I have a Finnish date representation (tiistaina, 27. lokakuuta 2015) that I need to convert to a datetime object. However, the names of days and months are not recognized by the datetime library in Python
I would expect something like the following:
import locale from datetime import datetime locale.setlocale(locale.LC_TIME, 'fi_FI') the_date = datetime.strptime('tiistaina, 27. lokakuuta 2015', '%A, %d. %B %Y')
However, this leads to:
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/_strptime.py", line 500, in _strptime_datetime tt, fraction = _strptime(data_string, format) File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/_strptime.py", line 337, in _strptime (data_string, format)) ValueError: time data 'tiistaina, 27. lokakuuta 2015' does not match format '%A, %d. %B %Y'
I think this is because Python expects the day to become thiistai instead of tiistai na , and the month to be lokakuu instead of lokakuu na
http://people.uta.fi/~km56049/finnish/timexp.html seems to suggest that, depending on the context, there are different ways to present the day or month in Finnish.
How can I use tiistaina, 27. lokakuuta 2015 string tiistaina, 27. lokakuuta 2015 for a datetime object?