[Django]-How to correctly format a datetime with Django and Python

5👍

In fact, the datetime use the representation of the object stored in tzinfo when you’re printing the datetime object in your Python shell.
Django uses its django.utils.timezone module to initialize dates and so the tzinfo attribute is equal to django.utils.timezone.utc (by default, when you haven’t specified any timezone).

When you’re looking to the __repr__ of utc you can see:

>>> from django.utils.timezone import utc
>>> repr(utc)
'<UTC>'

Hence the tzinfo=<UTC>. It’s a string representation, not a real Python value.

Leave a comment