1

timedelta.total_seconds() is not supported in python 2.6. The code below works in python 2.7. Would anybody know how to convert to equivalent in 2.6?

Thanks

import datetime

timestamp = 1414270449
timestamp = int((datetime.datetime.strptime(timestamp, '%Y-%m-%d %H:%M:%S') - datetime.datetime(1970,1,1)).total_seconds())

Sorry,

I have the same code below. How do I implement total_seconds() in python 2.6 using

(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

Thanks

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
scalauser
  • 449
  • 1
  • 12
  • 23
  • why do you call `strptime()` on integer? – jfs Jan 21 '15 at 13:06
  • related: [Converting datetime.date to UTC timestamp in Python](http://stackoverflow.com/a/8778548/4279) – jfs Jan 21 '15 at 13:09
  • possible duplicate of [alternative to total\_seconds() in python 2.6](http://stackoverflow.com/questions/28089558/alternative-to-total-seconds-in-python-2-6) – Yoriz Jan 22 '15 at 13:26

1 Answers1

8

It's all in the docs:

Equivalent to (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6 computed with true division enabled.

Tim Pietzcker
  • 328,213
  • 58
  • 503
  • 561