I have a form with dropdowns full of times, represented with datetime.time objects.
What's the best way to serialize the object? eg:
<option value="${time.serialize()}">${time.isoformat()}</option>
And then deserialize it on the other end? eg:
time = datetime.time.deserialize(request.params['time'])
If you repr
a datetime.time
object, Python gives you isoformat
. As repr
s attempt to be serialized versions of their objects, that's a good indication it's the value you should use.
import datetime
timestring = datetime.datetime.now().time().isoformat()
timeobj = datetime.datetime.strptime(timestring, "%H:%M:%S.%f").time()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With