0

I am getting time input in unix (milliseconds) and want to get time difference b/w given value and current time for that I did following. 1st convert posix into human readable then tried to minus 2 values but - doesn't go well with str.

/1000 is for millisecond reduction

t = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(1496814300000/1000))
k = datetime.datetime.now()

j = k -t
print j
Ahsan Naseem
  • 1,046
  • 1
  • 19
  • 38

2 Answers2

1

Try turning your timestamp into a datetime object directly:

import datetime
t = datetime.datetime.fromtimestamp(1496814300000/1000)
k = datetime.datetime.now()

j = k - t
print(j)
acdr
  • 4,538
  • 2
  • 19
  • 45
0

Found solution here

how to convert a string date into datetime format in python?

strptime is the key to convert string into datetime

Ahsan Naseem
  • 1,046
  • 1
  • 19
  • 38