Reputation: 4663
Here is my code:
# Given an Unix timestamp in milliseconds (ts), return a human-readable date and time (hrdt)
def parseTS(ts):
hrdt = time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.time(int(ts)/1000))
return str(hrdt)
I am getting this error:
TypeError: time() takes no arguments (1 given)
UPDATE:
This worked:
hrdt = datetime.datetime.fromtimestamp(int(ts)//1000)
return hrdt
Upvotes: 1
Views: 1235
Reputation: 5845
The time.time(int(ts)/1000) function is wrong.
Try one of time.ctime, time.gtime() or time.localtime() functions to achieve what you want.
Upvotes: 4
Reputation: 54242
The problem is this:
time.time(int(ts)/1000)
And (as the error is telling you), time() takes no arguments.
It's unclear what you're trying to do, but maybe you want:
int(time.time() / 1000)
Or just int(time.time())
if you want the time in seconds without the floating point part.
Upvotes: 0
Reputation: 11896
As the error says, time.time() doesn't take any arguments, it just returns current time as floating point. Maybe you are thinking of time.ctime()?
Upvotes: 0