Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django timestamp

Is there a way to use the Django timestamp without using a model? I want to write the timestamp to a file. The reason I want to use the Django one and not datetime or time from python is because I already set the Time Zone for it in settings so it would be more convenient if I could just use that.

like image 559
Talha Ahmed Avatar asked Aug 23 '26 01:08

Talha Ahmed


1 Answers

Yes

from django.utils import timezone

now = timezone.now()

Also make sure that USE_TZ=True. This is automatically set to False. If this isn't set to True then timezone.now() will not be set to your timezone.

like image 62
kevswanberg Avatar answered Aug 25 '26 17:08

kevswanberg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!