Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to format date in different languages?

I have a Django project with settings set to lang 'pl', in every template I use localized date format, for example:

{{ item.date|date:'D, d N H:i:s e' }}

result:
    Wt, 13 Lis 2012 22:00:00

But in only one template I must use format for lang 'en':

Thu, 13 Nov 2012 22:00:00 GMT

How can I accomplish this?

like image 615
Nips Avatar asked Nov 13 '12 21:11

Nips


People also ask

How do you write dates in different formats?

The international standard recommends writing the date as year, then month, then the day: YYYY-MM-DD. So if both Australians and Americans used this, they would both write the date as 2019-02-03. Writing the date this way avoids confusion by placing the year first.

What is yyyy mmm dd format?

YYYY/MMM/DD. Four-digit year, separator, three-letter abbreviation of the month, separator, two-digit day (example: 2003/JUL/25) DD/MMM/YYYY. Two-digit day, separator, three-letter abbreviation of the month, separator, four-digit year (example: 25/JUL/2003)

How do you write the date in foreign?

The international format yyyy-mm-dd or yyyymmdd is also accepted, though this format is not commonly used. The formats d. 'month name' yyyy and in handwriting d/m-yy or d/m yyyy are also acceptable.)

What countries use YYYY-MM-DD format?

The United States is one of the few countries that use “mm-dd-yyyy” as their date format–which is very very unique! The day is written first and the year last in most countries (dd-mm-yyyy) and some nations, such as Iran, Korea, and China, write the year first and the day last (yyyy-mm-dd).


2 Answers

This helps for me:

{% load i18n %}

{% language 'en' %}
  {{ item.date|date:'D, d N H:i:s e' }}
{% endlanguage %}

For more details, see the Django online documentation.

like image 158
mmtootmm Avatar answered Nov 12 '22 07:11

mmtootmm


This help for me, in that view where I use lang 'en' and load template:

from django.conf import settings

settings.LANGUAGE_CODE = 'en'
settings.USE_L10N = False
settings.USE_I18N = False
like image 28
Nips Avatar answered Nov 12 '22 07:11

Nips