<legend id='SHcj0'><style id='SHcj0'><dir id='SHcj0'><q id='SHcj0'></q></dir></style></legend><tfoot id='SHcj0'></tfoot>

    <bdo id='SHcj0'></bdo><ul id='SHcj0'></ul>

      <i id='SHcj0'><tr id='SHcj0'><dt id='SHcj0'><q id='SHcj0'><span id='SHcj0'><b id='SHcj0'><form id='SHcj0'><ins id='SHcj0'></ins><ul id='SHcj0'></ul><sub id='SHcj0'></sub></form><legend id='SHcj0'></legend><bdo id='SHcj0'><pre id='SHcj0'><center id='SHcj0'></center></pre></bdo></b><th id='SHcj0'></th></span></q></dt></tr></i><div id='SHcj0'><tfoot id='SHcj0'></tfoot><dl id='SHcj0'><fieldset id='SHcj0'></fieldset></dl></div>

      <small id='SHcj0'></small><noframes id='SHcj0'>

      从 Binance-API (Python) 计算时间戳之外的日期

      时间:2023-09-14
      <tfoot id='gMnli'></tfoot>
        <tbody id='gMnli'></tbody>
      <i id='gMnli'><tr id='gMnli'><dt id='gMnli'><q id='gMnli'><span id='gMnli'><b id='gMnli'><form id='gMnli'><ins id='gMnli'></ins><ul id='gMnli'></ul><sub id='gMnli'></sub></form><legend id='gMnli'></legend><bdo id='gMnli'><pre id='gMnli'><center id='gMnli'></center></pre></bdo></b><th id='gMnli'></th></span></q></dt></tr></i><div id='gMnli'><tfoot id='gMnli'></tfoot><dl id='gMnli'><fieldset id='gMnli'></fieldset></dl></div>

          <small id='gMnli'></small><noframes id='gMnli'>

            <legend id='gMnli'><style id='gMnli'><dir id='gMnli'><q id='gMnli'></q></dir></style></legend>
                <bdo id='gMnli'></bdo><ul id='gMnli'></ul>
                本文介绍了从 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) 计算时间戳之外的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:无法使用 Series 内置函数对时间戳应用方法 下一篇:windows下用python修改文件创建/访问/写入时间戳

                相关文章

                最新文章

                1. <legend id='iiM9n'><style id='iiM9n'><dir id='iiM9n'><q id='iiM9n'></q></dir></style></legend>
                2. <tfoot id='iiM9n'></tfoot>

                  <small id='iiM9n'></small><noframes id='iiM9n'>

                  <i id='iiM9n'><tr id='iiM9n'><dt id='iiM9n'><q id='iiM9n'><span id='iiM9n'><b id='iiM9n'><form id='iiM9n'><ins id='iiM9n'></ins><ul id='iiM9n'></ul><sub id='iiM9n'></sub></form><legend id='iiM9n'></legend><bdo id='iiM9n'><pre id='iiM9n'><center id='iiM9n'></center></pre></bdo></b><th id='iiM9n'></th></span></q></dt></tr></i><div id='iiM9n'><tfoot id='iiM9n'></tfoot><dl id='iiM9n'><fieldset id='iiM9n'></fieldset></dl></div>

                      <bdo id='iiM9n'></bdo><ul id='iiM9n'></ul>