How to format current time in django views?

蓝咒 提交于 2021-02-05 09:24:27

问题


I'm unable to figure out that how to format present time in django views. I just want to show year-month-date or (y,m,d) .Can you guys tell me how to do this ?

Right now i'm trying in a following way.

from django.utils import timezone
print('date :',timezone.now())
and it returns : 
date : 2020-12-31 18:34:29.309006+00:00

Desire output is : date : 2020-12-31


回答1:


from datetime import datetime
my_date = datetime.now().strftime("%Y-%m-%d")


来源:https://stackoverflow.com/questions/65524569/how-to-format-current-time-in-django-views

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!