这是我的情况:我在 MSSQL 中存储了一些日期时间,我通过 SQLAlchemy 在我的 python 应用程序中获取了这些日期时间,然后通过 Marshmallow 将其序列化,如下所示:
class MyVisitSchema(Schema):
cafe = fields.Nested(CafeSchema)
started_at = fields.DateTime()
ended_at = fields.DateTime()
class Meta:
additional = ('duration',)
ordered = True
但是这里的问题是:在序列化之后,我得到类似"started_at": "1994-05-20T00:00:00+00:00"
UTC+0 的信息,但是我将所有日期都存储在 DB 中,没有任何时区信息,而是在 UTC+3 中。
我知道我可以fields.Method()
用来更改输出时区,但它看起来不方便。有什么想法可以让我的序列化程序正常工作吗?)