Timezone.now() vs datetime.datetime.now()

只谈情不闲聊 提交于 2019-12-04 01:05:13

Just always use timezone.now(). Django now has timezone support which requires timezone 'aware' datetime objects. datetime.now() will return a timezone naive object, whereas timezone.now() will return a timezone aware object.

You can write in shell, for example:

timezone.datetime.now() < timezone.now() 

And the error message is:

TypeError: can't compare offset-naive and offset-aware datetimes

They are different objects, only timezone.now() have UTC support

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