The error is due to the milliseconds which push the number out of the range of 32-bit integers. datetime.datetime.fromtimestamp
expects the first argument to be the number of seconds since the begin of the UNIX epoch. However, it is capable of handling fractions of a second given as floating point number. Thus, all you have to do is to divide your timestamp by 1000:
import datetime
var = 1458365220000
temp = datetime.datetime.fromtimestamp(var / 1000).strftime('%H:%M:%S')
print (temp)
If you also want to include the milliseconds in your formatted string, use the following format: '%H:%M:%S.%f'