Reputation: 948
I am having difficulty formatting the current time in Django views and am seeking guidance on how to do so. Specifically, I am trying to display the date in the format 'year-month-date' or 'y,m,d'. Could you please provide guidance on how to achieve this?
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
Upvotes: 0
Views: 135
Reputation: 672
from datetime import datetime
my_date = datetime.now().strftime("%Y-%m-%d")
Upvotes: 3