Datetime.datetime.now() is five minutes off

I'm currently developing a django backend. I use auto_now_add=True in my model to populate a start point on create(). I use datetime.datetime.now() to add an endpoint on update(). The entire code for that is datetime.datetime.now().replace(tzinfo=pytz.timezone(settings.TIME_ZONE).

Here's an example for an instance that was created at 2023-01-21T19:26:04.561888Z and updated only seconds later.

enter image description here

As you can see, the endpoint populated on update() is somehow before the startpoint, which is not intended behavior.

Thank you

I managed to get it to work by using timezone.now() from django.utils.timezone. It still uses pytz in the background but it seems to be working. It's the same function auto_add_now uses.

Back to Top