Python strptime finnish

后端 未结 2 2013
情深已故
情深已故 2021-01-23 07:39

I have a Finnish representation of a date (tiistaina, 27. lokakuuta 2015) that I need to convert to a datetime object. However, the day and month names are not recognis

2条回答
  •  悲&欢浪女
    2021-01-23 08:09

    The days of week and month names are substituted in nominative case for %A and %B respectively; however that date format has DOW in the essive case, and the month in partitive. Declension in Finnish is quite complicated in general case, but for this case, you can suffix a DOW name with na to get the required essive, and ta to the month to get the partitive.

    Thus the strptime format '%Ana, %d. %Bta %Y' with the fi_FI locale is guaranteed to work for all your dates:

    >>> datetime.datetime.strptime('tiistaina, 27. lokakuuta 2015', '%Ana, %d. %Bta %Y')
    datetime.datetime(2015, 10, 27, 0, 0)
    

提交回复
热议问题