gpt4 book ai didi

Python/postgres : Any advantage to converting mxDateTime to built in datetime objects?

转载 作者:行者123 更新时间:2023-11-29 12:14:50 26 4
gpt4 key购买 nike

我继承的一些代码使用 Python 的 psycopg2 模块从 Postgres 数据库查询返回 mxDateTime 对象。我猜这种行为是出于历史原因,但想知道是否还有其他解释。鉴于我已经通过我继承的大型库具有 mxDateTime 依赖项,在对这些日期进行操作之前转换为内置日期时间数据类型是否有任何优势?

最佳答案

有很大的理由不改变它,这不是历史原因。内置的 Python 时间戳通常只有 32 位。

Postgresqls 时间戳:

min value 4713 BC

max value: 5874897 AD

http://www.postgresql.org/docs/current/static/datatype-datetime.html#DATATYPE-DATETIME-TABLE

Python 的:

classmethod date.fromtimestamp(timestamp)¶

... It’s common for this to be restricted to years from 1970 through 2038. Note that on non-POSIX systems that include leap seconds in their notion of a timestamp, leap seconds are ignored by fromtimestamp().

http://docs.python.org/library/datetime.html#datetime.date.fromtimestamp

在带有 Python 2.5 的 Windows 7 上:

>>>> date.fromtimestamp(0)
datetime.date(1969, 12, 31)
>>> date.fromtimestamp(-1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: timestamp out of range for platform localtime() function

关于Python/postgres : Any advantage to converting mxDateTime to built in datetime objects?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4505345/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com