作者:lajallan608 | 来源:互联网 | 2023-07-03 12:20
WhenshouldIbeusingdjangostimezone.now()andwhenshouldIbeusingpythongsdatetime.datetim
When should I be using django's timezone.now()
and when should I be using pythong's datetime.datetime.now()
.
我何时应该使用django的timezone.now()以及何时应该使用pythong的datetime.datetime.now()。
For example, in the following INSERT
which would make more sense?
例如,在下面的INSERT中会更有意义吗?
- Product.objects.create(title='Soap', date_added=datetime.datetime.now())
- Product.objects.create(title='Soap', date_added=timezone.now())
Is there a rule of thumb on when to use each?
是否有关于何时使用每种方法的经验法则?
1 个解决方案