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
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)
Found solution here
how to convert a string date into datetime format in python?
strptime is the key to convert string into datetime
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.