Display Python datetime without time
If you need the result to be timezone-aware, you can use the replace()
method of datetime
objects. This preserves timezone, so you can do
>>> from django.utils import timezone>>> now = timezone.now()>>> nowdatetime.datetime(2018, 8, 30, 14, 15, 43, 726252, tzinfo=<UTC>)>>> now.replace(hour=0, minute=0, second=0, microsecond=0)datetime.datetime(2018, 8, 30, 0, 0, tzinfo=<UTC>)
Note that this returns a new datetime object -- now
remains unchanged.