Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python month/day names in other language [duplicate]

Debian is set to en_US but I need day/month in German.

So how can I get %a to output Do instead of Thu?

draw.text((0,34), time.strftime("%a %d.%m.%Y"), font=font)
like image 919
MrGlasspoole Avatar asked May 24 '18 07:05

MrGlasspoole


People also ask

How to get month name from date in Python?

Get Month Name from Date in Python To get the month name from a number in Python, the easiest way is with strftime() and passing "%M". You can also use the calendar module.

How to iterate over the number of months in Python?

The user gives the input for the month number. datetime.strptime () is called. It takes month number and month format "%m" as arguments. Passing "%b" to strftime returns abbreviated month name while using "%B" returns full month name. This method imports calender module. It simply uses a for loop to iterate over the number of months (12).

How to work with dates in Python?

In Python, we can work on Date functions by importing a built-in module datetime available in Python. We have date objects to work with dates. This datetime module contains dates in the form of year, month, day, hour, minute, second, and microsecond. Let us discuss different ways to convert a month number to a month name.

How to set language for day and month names in SQL?

SQL developers can use following T-SQL statements including "Set Language" for setting a specific language which the day and month names will be automatically translated into. SQL DateName datetime function is used to return text descriptions of months or week days in SQL Server database development.


1 Answers

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'
>>> 
like image 193
Rolf of Saxony Avatar answered Nov 05 '22 00:11

Rolf of Saxony