Format date with month name in polish, in python

后端 未结 3 1320
迷失自我
迷失自我 2021-01-14 01:24

Is there an out of the box way to format in python (or within django templates), a date with full month name in accordance to polish language rules?

I want to get:

3条回答
  •  北荒
    北荒 (楼主)
    2021-01-14 01:58

    OP's code now works as he intended: returning '30 kwietnia 2020' and not 30 kwiecień 2020. Tested today with Python 2.7 and Python 3.6. Setting locale was required, I used the platform one - this might be an issue with web-apps as per other answers.

    $ python
    Python 2.7.17 (default, Apr 15 2020, 17:20:14) 
    [GCC 7.5.0] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> [cut repeated code]
    $ python3.6
    Python 3.6.9 (default, Apr 18 2020, 01:56:04) 
    [GCC 8.4.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import datetime
    >>> datetime.datetime.today()
    datetime.datetime(2020, 4, 30, 18, 13, 21, 308217)
    >>> datetime.datetime.today().strftime("%d %B %Y")
    '30 April 2020'
    >>> import locale
    >>> locale.setlocale(locale.LC_ALL, '')
    'pl_PL.UTF-8'
    >>> datetime.datetime.today().strftime("%d %B %Y")
    '30 kwietnia 2020'
    

提交回复
热议问题