简体   繁体   English

如何防止django,将日期转换为utc格式

[英]how to prevent django, convert date to utc format

I get my date with time zone: "datetime": "2019-07-04T17: 53: 06-05: 00", when choosing save method, but in my bd oracle it is saved: "2019-07-04T22: 53: 06". 我得到了我的约会时区:“datetime”:“2019-07-04T17:53:06-05:00”,选择保存方法时,但在我的bd oracle中保存了它:“2019-07-04T22:53 :06“。

I have already set USE_TZ: False. 我已设置USE_TZ:False。

serializer = self.serializer_class(data=json_data)
if serializer.is_valid():
pas_documento_guardado = serializer.save(usuario=usuario, tercero=tercero)

I hope it is saved in the database: "datetime": "2019-07-04T17: 53: 06", 我希望它保存在数据库中:“datetime”:“2019-07-04T17:53:06”,

Probably you have to define the proper TIME_ZONE in your Django settings.py file. 可能你必须在Django settings.py文件中定义正确的TIME_ZONE

From Django Docs : 来自Django Docs

Since Django was first released with the TIME_ZONE set to 'America/Chicago', the global setting (used if nothing is defined in your project's settings.py) remains 'America/Chicago' for backwards compatibility. 由于Django首次发布时TIME_ZONE设置为“America / Chicago”,因此全局设置(如果项目的settings.py中未定义任何内容,则使用该设置)仍然是“America / Chicago”的向后兼容性。 New project templates default to 'UTC'. 新项目模板默认为“UTC”。

and also: 并且:

When USE_TZ is False, this is the time zone in which Django will store all datetimes. 当USE_TZ为False时,这是Django存储所有日期时间的时区。

Hope it helps. 希望能帮助到你。

After continuing researching, I found the solution, the property 'TIME_ZONE' must be included in the properties of DATABASES in settings.py 在继续研究之后,我找到了解决方案,属性'TIME_ZONE'必须包含在settings.py中DATABASES的属性中

DATABASES = {
'legacy': {
    'ENGINE': 'django.db.backends.mysql',
    'OPTIONS': {
        'read_default_file': '....cnf',
    },
    'TIME_ZONE': 'America/Bogota',
},
'default' : {
    'ENGINE': 'django.db.backends.mysql',
    'OPTIONS': {
        'read_default_file': '....cnf',
    },
}

Thanks for the help. 谢谢您的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM