当前位置: 动力学知识库 > 问答 > 编程问答 >

How to Create Negative Epoch Value in python

问题描述:

I am trying to create epoch values for a date field using Python. It works great for all the dates after '1970-01-01'. Any date before 1970 doesn't work.

Here is the code I am using:

int(time.mktime(time.strptime('1969-01-01', '%Y-%m-%d'))) - time.timezone

Error:

OverflowError: mktime argument out of range

Is there any alternative way to create negative epoch value?

网友答案:

From the documentation of the time module:

The functions in this module may not handle dates and times before the epoch or far in the future.

So that's out. I would suggest using the datetime module instead, which can handle dates in years between 1 and 9999. I'm afraid without knowing your use case we can't be of more help.

分享给朋友:
您可能感兴趣的文章:
随机阅读: