Thanks for your help.
I'm new to Python.
I am trying to save the contract information and the time information at that time in a list from the Bitflyer API in Python.
I would like to include the decimal time in the time information.
I don't know how to change the datetime.
For example, second = float (data [17:22]) will also result in an error.
Can anyone give me a hint?
What is the value of the date?
"2020-11-22T02: 18: 34.967"
import requests from datetime import datetime, timedelta import time price_list =  #Empty list creation data_list =  # Create an empty list response = requests.get ("https://api.bitflyer.com/v1/getexecutions") #bitfyer API launch response = response.json () #Json support price = response  ["price"] # Get final price date = response  ["exec_date"] #Get trading time i = 0 while i>-101: price = response [int (i)] ["price"] # Get final price date = response [int (i)] ["exec_date"] #Get trading time utc_split = datetime ( year = int (date [0: 4]), month = int (date [5: 7]), day = int (date [8:10]), hour = int (date [11:13]), minute = int (date [14:16]), second = int (date [17:19]) ) exec_data = utc_split + timedelta (hours = + 9) #time difference calculation price_list.append (price) #Display price list tstr = exec_data.strftime ('% Y-% m-% d% H:% M:% S') #Time data string conversion data_list.append (tstr) #Display time data i = i -1 print (price_list) print (data_list)
Traceback (most recent call last): File "bit_befor.py", line 17, in<module> utc_split = datetime ( TypeError: integer argument expected, got float
Answer # 1
Can't you use strptime?
from datetime import datetime, timedelta date = '2020-11-22T13: 24: 07.13' dt = datetime.strptime (date,'% Y-% m-% dT% H:% M:% S.% f') print (dt) # 2020-11-22 13: 24: 07.130000
Answer # 2
Values smaller than seconds should be values in microseconds
microsecond =Specify in.
datetimeIf you don't know how to use
datetimeLet's see the section.
Answer # 3
In the case of datetime.datetime (), you can set the values for year, month, day, hour, minite, second, and microsecond respectively.
date = "2020-11-22T02: 18: 34.967" utc_split = datetime (year = int (date [0: 4]), month = int (date [5: 7]), day = int (date [8:10]), hour = int (date [11:13]] ), minute = int (date [14:16]), second = int (date [17:19]), microsecond = int (date [20:])) print (utc_split) # datetime.datetime (2020, 11, 22, 2, 18, 34, 967)
- python - how to handle decimal with json serialization
- python - "type error: expect dataindex as datetime index" error does not disappear
- python - how to handle functions and lists
- conversion from python datetime type to timedelta type
- python - i want to handle strings with scipy
- python - connect the plotted points
- how to calculate datetime in python ~ datetime error ~
- conversion between numeric and datetime types in python
- python - how to convert exponential notation to decimal notation
- python - i want to handle webdriverchrome ()
- datetime - attribute error of "python practice data analysis 100 knocks"
- python - i want to handle files with the path obtained by ospathjoin
- i want to paint the vertices (contact points) of a figure with a specific shape from within a two-dimensional array created usin
- python : Ignore none when converting date in DataFrame
- Python: Building a vertical strip using MATPLOTLIB for the axis on which time is displayed
- python : Implementation of the API Django.
- python : It's impossible to make the right API request
- python : Exmo API. I can not legitiate
- python : How to translate unixtimestamp values at the date?
- python : Download Django Server File
- python : Sort the array by date with the enclosed JSON?
- You need to write a UI test on Python for https://www.metric-conversions.org/Test for conversion of temperature Celsius temperat
- python : How to make the program to display a greeting only when the user writes "hello" or "Hello"? [duplicate]