datetime - Compare string in format HH:MM to time now in python -
i have string of format "hh:mm" , need compare time in python.
i did read through datetime documentation not figure out elegant perform comparison (being total rookie not either:))
thanks reading this!
you can use datetimes
's strptime()
function convert string valid datetime
:
>>>d=datetime.datetime.strptime('15:30','%h:%m')
and later compare now
's time()
:
>>>dnow=datetime.datetime.now() #11:42 here ;) >>>dnow.time() < d.time() true
you can read doc's strftime() , strptime() behavior explained these methods , have table resuming directives parse dates.
Comments
Post a Comment