Why django DateTimeField
restore tzinfo
in datetime
to <utc>
?
Below is my test code.
Is it normal or wrong.?
If it is normal, what is the reason?
models.py
class Date(models.Model):
datetime = models.DateTimeField()
settings.py
TIME_ZONE = 'Asia/Seoul'
USE_TZ = True
test.py
from django.utils import timezone
datetime = timezone.localtime(timezone.localtimezone.now())
#now datetime is datetime.datetime(2015, 10, 22, 20, 31, 56, 248000, tzinfo=<DstTzInfo 'Asia/Seoul' KST+9:00:00 STD>)
models.Date(datetime=datetime).save()
#If I check datebase, It shows 2015-10-22 11:31:56.248000
model.Date.object.get(..)
#It returns datetime.datetime(2015, 10, 22, 11, 31, 56, 248000, tzinfo=<UTC>)
I expect django stores 2015-10-22 20:31:56.248000
and return datetime.datetime(2015, 10, 22, 20, 31, 56, 248000, tzinfo=<DstTzInfo 'Asia/Seoul' KST+9:00:00 STD>)
--------------Edit----------------
I used Sqlite
.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…