我正在尝试使用 Python 为日期字段创建纪元值。它适用于“1970-01-01”之后的所有日期。 1970 年之前的任何日期均无效。
这是我使用的代码:
int(time.mktime(time.strptime('1969-01-01', '%Y-%m-%d'))) - time.timezone
错误:
OverflowError: mktime argument out of range
有没有其他方法可以创造负的 epoch 值(value)?
请您参考如下方法:
来自 time 的文档模块:
The functions in this module may not handle dates and times before the epoch or far in the future.
这样就结束了。我建议使用 datetime模块,它可以处理 1 到 9999 之间的年份日期。恐怕在不了解您的用例的情况下,我们无法提供更多帮助。
