Force date and time formats to ISO

73 views
Skip to first unread message

Mark Caglienzi

unread,
Sep 29, 2014, 1:13:22 PM9/29/14
to django...@googlegroups.com
Hello to the list,
I am developing a Django website that needs USE_L10N = True, and
per-user TZ settings, but I want to force the output of dates and times
to ISO everywhere, once and for all (YYYY-MM-DD and HH:MM:SS).

I understand that Django with USE_L10N = True overrides the output of
DateField, DateTimeField, TimeField to follow the locale format, but I
need the format of my choice everywhere.

For the output in templates I came to this solution: write a
templatefilter that does the localtime -> strftime steps, and it works.

But to be the definitive solution also form fields when doing CRUD on my
database objects must accept and show dates and datetimes in that format.

I'm thinking that I have to write custom form fields like
ISO_DateField(django.forms.DateField),
ISO_DateTimeField(django.forms.DateTimeField) and
ISO_TimeField(django.forms.TimeField) overriding their methods to do
what I need.

Is there a better way?

Thanks in advance,
Mark

Collin Anderson

unread,
Sep 29, 2014, 4:17:23 PM9/29/14
to django...@googlegroups.com
If it helps, the ISO format should always at least be _accepted_ as an input, even it it's not displayed that way.

Mark Caglienzi

unread,
Sep 29, 2014, 10:19:53 PM9/29/14
to django...@googlegroups.com
On 29 Sep 13:17, Collin Anderson wrote:
> If it helps, the ISO format should always at least be _accepted_ as an
> input, even it it's not displayed that way.

Yes, I agree, but the main point (for what I need) is also the display of the
date and times.

This will allow to keep the webapp forms/tables uniform (it's a
requirement) and also ease the use of javascript widgets for the date
and time fields (one format, coherent).

Collin Anderson

unread,
Oct 1, 2014, 8:35:30 AM10/1/14
to django...@googlegroups.com
I wonder if it's possible to somehow use a custom locale that will always show ISO dates.

Mike Dewhirst

unread,
Oct 1, 2014, 8:59:50 AM10/1/14
to django...@googlegroups.com
On 1/10/2014 10:35 PM, Collin Anderson wrote:
> I wonder if it's possible to somehow use a custom locale that will
> always show ISO dates.

I believe some of the Scandinavian countries use ISO natively ...


>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users...@googlegroups.com
> <mailto:django-users...@googlegroups.com>.
> To post to this group, send email to django...@googlegroups.com
> <mailto:django...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/3b2783ba-d553-4315-a40e-abd16c0922d6%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/3b2783ba-d553-4315-a40e-abd16c0922d6%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

Jan Eskilsson

unread,
Oct 2, 2014, 6:06:29 AM10/2/14
to django...@googlegroups.com
Sweden does

2014-10-01 16:59 GMT+04:00 Mike Dewhirst <mi...@dewhirst.com.au>:
On 1/10/2014 10:35 PM, Collin Anderson wrote:
I wonder if it's possible to somehow use a custom locale that will
always show ISO dates.

I believe some of the Scandinavian countries use ISO natively ...



--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send

To post to this group, send email to django...@googlegroups.com
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
No trees were killed in the creation of this message.
However, many electrons were terribly inconvenienced.
 
Please consider the environment before you print this email.
 
(1) The contents of this transmission are privileged and confidential and intended solely for the use of the addressee. Any disclosure, distribution or copying of the contents, other than by the addressee, is strictly prohibited. If you receive this transmission in error, please notify us immediately and destroy the material received.
(2) All incoming and outgoing emails and any attachments are subjected to a virus scanner and are believed to be free of any virus, or any other defect which might affect any computer or IT system into which they are received and opened. Therefore, it is the responsibility of the recipient to ensure that they are virus free and no responsibility is accepted by Jan Eskilsson  for any loss or damage arising in any way from receipt or use thereof.

Erik Cederstrand

unread,
Oct 2, 2014, 9:07:25 AM10/2/14
to Django Users
Den 01/10/2014 kl. 14.59 skrev Mike Dewhirst <mi...@dewhirst.com.au>:

> On 1/10/2014 10:35 PM, Collin Anderson wrote:
>> I wonder if it's possible to somehow use a custom locale that will
>> always show ISO dates.
>
> I believe some of the Scandinavian countries use ISO natively ...

Except the OP probably doesn't want our monetary and numeric formats. Have a look at custom format files (https://docs.djangoproject.com/en/1.7/topics/i18n/formatting/#creating-custom-format-files) to override the DATE_FORMAT and DATETIME_FORMAT settings (https://docs.djangoproject.com/en/1.7/ref/settings/#std:setting-DATE_FORMAT).

Erik
Reply all
Reply to author
Forward
0 new messages