Over here: https://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior it says that %p
displays AM / PM. It shows this
AM, PM (en_US);
am, pm (de_DE)
I'm not sure what de_DE
is, but when I do %p
using Django Rest Framework it shows AM and PM in capital letters. How do I change it so that am and pm are displayed in lowercase?
This is my DRF settings.py
code where I edit the datetime format (might not be useful):
#added REST_FRAMEWORK
REST_FRAMEWORK = {
'DEFAULT_RENDERER_CLASSES': (
'rest_framework.renderers.JSONRenderer',
'rest_framework.renderers.BrowsableAPIRenderer',
),
'DATETIME_FORMAT': "%b %d at %I:%M %p"
}
Try changing '%p' to '%P'. Whether '%P' is supported depends on the 'strftime' function provided by the platform C library.
I'm pretty sure that you cannot. The %p
format code is the locale-specific "national representation of either "ante meridiem" (a.m.) or "post meridiem" (p.m.) as appropriate". de_DE
is the generic German locale which is what defines the national representation which happens to be lowercase. The en_US
locale has it defined in uppercase. Part of using functions like strftime
is that they take care of the localization details for you.
The documentation does explicitly mention that the exact values are entirely locale specific:
Because the format depends on the current locale, care should be taken when making assumptions about the output value. Field orderings will vary (for example, “month/day/year” versus “day/month/year”), and the output may contain Unicode characters encoded using the locale’s default encoding (for example, if the current locale is ja_JP, the default encoding could be any one of eucJP, SJIS, or utf-8; use locale.getlocale() to determine the current locale’s encoding).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With