【发布时间】:2021-08-08 01:36:11
【问题描述】:
我正在尝试将 unix 纪元时间从 JSON 转换为正常日期。
JSON 代码(不完整):
{"success":true,"lastUpdated":1621365664405
我有这个代码:
import requests
import json
from datetime import datetime
r = requests.get('https://api.hypixel.net/skyblock/bazaar').json()
#last updated datetime
time = r['lastUpdated']
datetime_time = datetime.fromtimestamp(time).strftime('%Y-%m-%d')
print(datetime_time)
但我收到以下错误:第 9 行,在 datetime_time = datetime.fromtimestamp(time).strftime('%Y-%m-%d')。 OSError: [Errno 22] 无效参数
【问题讨论】:
-
请调试并找到产生错误的行。
-
编辑问题
-
r['lastUpdated']实际上是什么样子的? -
编辑了问题。
标签: python json python-3.x datetime