python 2.6 不支持 timedelta.total_seconds()。下面的代码适用于 python 2.7。有人知道如何转换为 2.6 中的等价物吗?
谢谢
import datetime
timestamp = 1414270449
timestamp = int((datetime.datetime.strptime(timestamp, '%Y-%m-%d %H:%M:%S') - datetime.datetime(1970,1,1)).total_seconds())
对不起,
我在下面有相同的代码。如何使用
在 python 2.6 中实现 total_seconds()(td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6`
import datetime
timestamp = '2014-10-24 00:00:00'
timestamp = int((datetime.datetime.strptime(timestamp, '%Y-%m-%d %H:%M:%S') - datetime.datetime(1970,1,1)).total_seconds())
print timestamp
timestamp = '2014-10-24 00:00:00'
timestamp = datetime.datetime.strptime(timestamp, '%Y-%m-%d %H:%M:%S') - datetime.datetime(1970,1,1)
print timestamp
谢谢
请您参考如下方法:
都是in the docs :
Equivalent to
(td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6computed with true division enabled.
