Python month/day 其他语言的名字

Python month/day names in other language

Debian 设置为 en_US 但我需要 day/month 德语

那么如何让 %a 输出 Do 而不是 Thu

draw.text((0,34), time.strftime("%a %d.%m.%Y"), font=font)

您可以使用下面的代码,然后继续使用 strftime:

import locale
# for German locale
locale.setlocale(locale.LC_TIME, "de_DE") 

如果您使用 windows,语法更改为:

locale.setlocale(locale.LC_ALL, 'deu_deu')

Linux

>>> import datetime
>>> import locale
>>> locale.setlocale(locale.LC_TIME, 'de_DE.UTF-8')
'de_DE.UTF-8'
>>> d = datetime.datetime.now()
>>> d.strftime("%a %d.%m.%Y")
'Do 24.05.2018'
>>>