alejoss alejoss - 1 year ago 137
Python Question

Python convert datetime.time to arrow

I need to convert a python object

to an arrow object.

y = datetime.time()
>>> y
datetime.time(0, 0)
>>> arrow.get(y)

TypeError: Can't parse single argument type of '<type 'datetime.time'>'

Answer Source

You can use the strptime class method of the arrow.Arrow class and apply the appropriate formattting:

y = datetime.time()
print(arrow.Arrow.strptime(y.isoformat(), '%H:%M:%S'))
# 1900-01-01T00:00:00+00:00

However, you'll notice the date value is default, so you're probably better off parsing a datetime object instead of a time object.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download