en_US
and de_DE
are locales.
en_US
= English US
de_DE
= German Germany
In the en_US
locale, AM/PM are uppercase whereas for the de_DE
locale, it's shown in lower case.
You can use locale.setlocale(locale.LC_ALL, 'de_DE')
to change your locale when you use time formatting and then revert it back after.
And to avoid issues with other date fields showing in the wrong order, like 'day,month,year' instead of the US-preferred 'month,day,year', when you use the time formatting options, make sure you specify all the fields and not one of the standard short/long time formats, since those will always be as per the locale. Example, %x
:
%x Locale’s appropriate date representation. 08/16/88 (None);
08/16/1988 (en_US);
16.08.1988 (de_DE)
However, doing this is not a good idea, since the month (for example) will appear in that language's name. So 'May' will appear as 'Mei' (affects both long and short forms).
A dirty workaround is to do a search and replace after the generating the timestring:
>>> datetime.strftime(datetime.today(), '%c %p').replace('AM', 'am').replace('PM', 'pm')
'08/10/16 10:37:49 am'
>>> datetime.strftime(datetime.today(), '%c %p').replace(' AM', ' am').replace(' PM', ' pm')
'08/10/16 10:39:19 am'
Again, not recommended since that will interfere with the timezone part where 'AM' and 'PM' occur - 'AMT', 'PMDT', 'GAMT'. If you're not displaying that or any other alphabets like for month, then it should be okay.