Compute Date out of Timestamp from Binance-API (Python)(从 Binance-API (Python) 计算时间戳之外的日期)
问题描述
我从 Binance-API 收到服务器时间,我尝试使用它,它看起来像这样:
I received the servertime from the Binance-API,I try to work with and it looks like this:
{
"serverTime": 1518440400000
}
问题是,我怎样才能从这张邮票中计算出日期?
The question is, how can I compute the date out of this stamp?
我试过了
import datetime
print(datetime.datetime.fromtimestamp(
int("1518308894652")).strftime('%Y-%m-%d %H:%M:%S'))
但日期无效.
你有什么想法,还是具体的?谢谢!
Do you have ideas, or is it to specific? Thank you!
推荐答案
你可以这样用:
from datetime import datetime
datetime.fromtimestamp(int("1518308894652"))
但是 python 说年份超出范围(可以理解,考虑到它说它是 50087).所以我怀疑 serverTime
不是正常的时间戳.
But python says the year is out of range (understandably, considering it says it's 50087). So I suspect that serverTime
is not a normal timestamp.
但假设您得到的响应是时间戳,所以除了将字符串转换为 int 之外,您不需要进行任何其他转换.
But assuming the response that you got was the timestamp, so you don't need to do any other conversions other than turning the string into an int.
原来文档说所有时间和时间戳相关的字段都以毫秒为单位".所以只需将响应除以 1000 就可以了:datetime.fromtimestamp(int("1518308894652")/1000)
.来源一个>
Turns out the docs say "All time and timestamp related fields are in milliseconds." So just divide the response by 1000 and you'll be fine: datetime.fromtimestamp(int("1518308894652")/1000)
. Source
这篇关于从 Binance-API (Python) 计算时间戳之外的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从 Binance-API (Python) 计算时间戳之外的日期


基础教程推荐
- 筛选NumPy数组 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01