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())