When i am fetching the stored datetime value from auth user in django the value comes as below is there a way to convert this into normal date time format may be like "dd:mm:yyyy hh:mm:ss"
or some string value that can be displayed in better(other) format
date_joined = request.user.date_joined
#date_joined value is
#datetime.datetime(2016, 9, 11, 16, 6, 22, 314637, tzinfo=<UTC>)
You can format a datetime object using its strftime()
method, for example like this:
date_joined = request.user.date_joined
date_joined.strftime("%d:%m:%y %H:M:S")
If you want to display a datetime object in Django template, you can use the builtin date
filter.
{{ date_joined|date:"d:m:Y H:i:s")
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.