Note that there are some explanatory texts on larger screens.

plurals
  1. POdate_format Django 1.4 with correct timezone
    primarykey
    data
    text
    <p>Okay simple question (I think).</p> <p>I have a DateTime field (auto_add_now) and when output to a template </p> <pre><code>{{ edited|date:"DATETIME_FORMAT" }} </code></pre> <p>I get the expected result of "Sept. 16, 2012, 12:01 p.m."</p> <p>But unfortunately things are slightly more complicated since I am using Backbone.js and need to pass the datetime with JSON, and since it is only used for display purposes I decided to pass it as a nice locale formatted string. So I dug into the code and found what the template tag uses and this is what I setup.</p> <pre><code>from django.utils.formats import date_format return { 'created': date_format(self.created, 'DATETIME_FORMAT'), } </code></pre> <p>But that ends up with this "Sept. 16, 2012, 5:01 p.m."</p> <p>I have a feeling it has to do with the following on the template tag</p> <pre><code>@register.filter(expects_localtime=True, is_safe=False) </code></pre> <p>I also tried this but ended up with the same results</p> <pre><code>from django.utils import timezone tz = timezone.get_current_timezone() logger.info(tz) logger.info(self.edited) logger.info(format(self.edited, 'DATETIME_FORMAT')) logger.info(self.edited.replace(tzinfo=tz)) logger.info(format(self.edited.replace(tzinfo=tz), 'DATETIME_FORMAT')) </code></pre> <p>Which gave me this</p> <pre><code>INFO: America/Chicago INFO: 2012-09-16 17:01:52.921276+00:00 INFO: Sept. 16, 2012, 5:01 p.m. INFO: 2012-09-16 17:01:52.921276-06:00 INFO: Sept. 16, 2012, 5:01 p.m. </code></pre> <p>So yeah, I must be missing something, and I have been up and down the django documentation and cannot find anything that could point me to what I am doing wrong. Thanks for any help.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload