0
我需要將python對象datetime.time
轉換爲arrow對象。Python將datetime.time轉換爲箭頭
y = datetime.time()
>>> y
datetime.time(0, 0)
>>> arrow.get(y)
TypeError: Can't parse single argument type of '<type 'datetime.time'>'
我需要將python對象datetime.time
轉換爲arrow對象。Python將datetime.time轉換爲箭頭
y = datetime.time()
>>> y
datetime.time(0, 0)
>>> arrow.get(y)
TypeError: Can't parse single argument type of '<type 'datetime.time'>'
可以使用arrow.Arrow
類的strptime
類方法並應用適當的formattting:
y = datetime.time()
print(arrow.Arrow.strptime(y.isoformat(), '%H:%M:%S'))
# 1900-01-01T00:00:00+00:00
但是,你會發現日期值是默認的,所以你可能會更好過解析一個datetime
對象而不是一個time
對象。
箭遵循特定的格式,其文件中規定:
arrow.get('2013-05-11T21:23:58.970460+00:00')
您需要將您的DateTime對象轉換爲箭頭可以理解的格式,以便能夠將其轉換爲一個箭頭對象。下面的代碼塊應該工作:
from datetime import datetime
import arrow
arrow.get(datetime.now())