I would like to send localized date in JSON from django view
Normal text translation via
ugettext
is OK
Following code in view has no effect:
translation.activate("ru") print datetime.now().strtime("%B")
Output is "August", instead of "Август"
I read about python's "locale" module, but it's named as thread unsafe
How to force strftime to use django's locale?
Use strftime() function of a datetime class The format codes are standard directives for mentioning in which format you want to represent datetime. For example, the %d-%m-%Y %H:%M:%S codes convert date to dd-mm-yyyy hh:mm:ss format.
You can use the date_format as follows. from django. utils import formats is the same? docs.djangoproject.com/en/dev/releases/1.2/…
DateTimeField in Django Forms is a date field, for taking input of date and time from user. The default widget for this input is DateTimeInput. It Normalizes to: A Python datetime. datetime object.
The formatting system is disabled by default. To enable it, it's necessary to set USE_L10N = True in your settings file. Note. To enable number formatting with thousand separators, it is necessary to set USE_THOUSAND_SEPARATOR = True in your settings file.
Finally i used date filter from django templates:
from django.template.defaultfilters import date as _date from datetime import datetime _date(datetime.now(), "d b, D")
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