简体   繁体   English

我在python中使用time()无法弄清楚这个错误

[英]I can't figure out this error using time() in python

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

The time.time(int(ts)/1000) function is wrong. time.time(int(ts)/ 1000)函数错误。

Try one of time.ctime, time.gtime() or time.localtime() functions to achieve what you want. 尝试使用time.ctime,time.gtime()或time.localtime()函数来实现您想要的功能。

Python Docs (Time) Python文档(时间)

As the error says, time.time() doesn't take any arguments, it just returns current time as floating point. 正如错误所说,time.time()不接受任何参数,它只是将当前时间作为浮点返回。 Maybe you are thinking of time.ctime()? 也许你在考虑time.ctime()?

The problem is this: 问题是这样的:

time.time(int(ts)/1000)

And (as the error is telling you), time() takes no arguments . 并且(正如错误告诉你的那样), time()不带参数

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. 或者只是int(time.time())如果你想要没有浮点部分的时间(以秒为单位)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM