简体   繁体   中英

Value Error :Time data '2019-03-19T07:01:02Z' does not match format '%Y-%m-%dT%H:%M:%S.%fZ'

I am using dateformat function but when i search for feb month only it shows proper data but when i search for march month it shows error and this is my timedate "date_joined": "2019-02-13T07:57:10.276212Z" which i want to format

Feb month date :"date_joined": "2019-02-13T07:57:10.276212Z",
march month date : "date_joined": "2019-03-18T08:19:55.297908Z",
dates are same but when i search i got this error on march month

This is my separate dateformat.py file in templatetag folder

from django.template import Library
import datetime

register = Library()

@register.filter(expects_localtime=True)
def dateformat(value):
    return datetime.datetime.strptime(value,"%Y-%m-%dT%H:%M:%S.%fZ")

and this is my table data line

<td>{{x.date_joined| dateformat|date:'d-m-Y' }}</td>

Error:

ValueError at /
time data '2019-03-19T07:01:02Z' does not match format '%Y-%m-%dT%H:%M:%S.%fZ'

%f is used for microsecond precision. But your time data "2019-03-19T07:01:02Z" doesn't have microseconds. Please change your code as:

@register.filter(expects_localtime=True)
def dateformat(value):
    return datetime.datetime.strptime(value,"%Y-%m-%dT%H:%M:%SZ")

This would work!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM