python datetime localization

前端 未结 4 1963
萌比男神i
萌比男神i 2021-02-20 15:47

What do I need to do (modules to load, locale methods to invoke, etc.) so that when I call:

datetime.date(2009,1,16).strftime(\"%A %Y-%b-%d\")

相关标签:
4条回答
  • 2021-02-20 16:09

    After setting your locale (with locale.setlocale) You can use the locale modules' nl_langinfo method like so:

    time.strftime(locale.nl_langinfo(locale.D_T_FMT), time.localtime())
    
    0 讨论(0)
  • 2021-02-20 16:16

    On Ubuntu,

    $> sudo locale-gen es_ES.UTF-8
    $> sudo dpkg-reconfigure locales
    $> python
    >>> import locale
    >>> locale.setlocale(locale.LC_TIME, 'es_ES.UTF-8')
    
    0 讨论(0)
  • 2021-02-20 16:17

    Also, have a look at the babel project.

    0 讨论(0)
  • 2021-02-20 16:26

    locale.setlocale()

    0 讨论(0)
提交回复
热议问题