python - 我无法在 python 中使用 time() 找出这个错误

标签 python time

这是我的代码:

# 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)

我收到这个错误:

TypeError: time() takes no arguments (1 given)

更新:

这有效:

hrdt = datetime.datetime.fromtimestamp(int(ts)//1000)
return hrdt

最佳答案

time.time(int(ts)/1000) 函数错误。

尝试使用 time.ctime、time.gtime() 或 time.localtime() 函数之一来实现您想要的效果。

Python Docs (Time)

关于python - 我无法在 python 中使用 time() 找出这个错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7655531/

相关文章:

python - 连接到本地主机上的套接字

javascript 一次性实现更多功能

javascript - 可以重置而不重叠的计时器? - JavaScript

java catch 进程时间实时进度条

python - 如何评论运算符之间的大赋值?

python - Plot.ly 的 Pandas GroupBy 对象不是 'serializable'

python - “DataFrame”对象不可调用

Python 3 - 在特定时间后打印 if

javascript - Moment.Js : Offsetting dates using UTC and Timezone offset

python - 递归二叉搜索树插入