#18951: Datetime microseconds cutoff first zero in Django templates
---------------------------------+-----------------------------------
     Reporter:  olofom@…         |      Owner:  nobody
         Type:  Bug              |     Status:  new
    Component:  Template system  |    Version:  1.4
     Severity:  Normal           |   Keywords:  datetime microseconds
 Triage Stage:  Unreviewed       |  Has patch:  0
Easy pickings:  0                |      UI/UX:  0
---------------------------------+-----------------------------------
 So I had a datetime object that I wanted to display on a web page and then
 post back through a hidden field. This didn't work (unless I use the 'c'
 flag with the date filter to get the ISO format, then it works fine).
 [[BR]]



 {{{
 >>> datetime.datetime(2013, 9, 12, 9, 24, 16, 14070)
 datetime.datetime(2013, 9, 12, 9, 24, 16, 14070)
 >>> str(datetime.datetime(2013, 9, 12, 9, 24, 16, 14070))
 '2013-09-12 09:24:16.014070'
 }}}

 [[BR]]


 BUT {{ timestamp|date:'Y-m-d H:i:s.u' }} prints:
 2013-09-12 09:24:16.14070
 without the first zero. Then when trying to convert this back to a
 datetime object I get:
 [[BR]]



 {{{
 >>> datetime.datetime.strptime('2013-09-12 09:24:16.14070', "%Y-%m-%d
 %H:%M:%S.%f")
 datetime.datetime(2013, 9, 12, 9, 24, 16, 140700)
 >>> str(datetime.datetime.strptime('2013-09-12 09:24:16.14070', "%Y-%m-%d
 %H:%M:%S.%f"))
 '2013-09-12 09:24:16.140700'
 }}}

 So in the end I ended up with the microseconds: 140700 instead of 014070,
 but the real bug is that the 'u' flag of date prints 14070 instead of
 014070.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/18951>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to