You can simply use:
import datetime the_time = datetime.time(6,30) value = the_time.hour + the_time.minute/60.0
If you want to take seconds and multiseconds, you can use:
import datetime the_time = datetime.time(6,30) value = the_time.hour + the_time.minute/60.0 + \ the_time.second/3600.0 + the_time.microsecond/3600000000.0
Both here generate:
>>> the_time.hour + the_time.minute/60.0 6.5 >>> the_time.hour + the_time.minute/60.0 + \ ... the_time.second/3600.0 + the_time.microsecond/3600000000.0 6.5
Or, if you want to print it with the suffix 'hrs' :
import datetime the_time = datetime.time(6,30) print('{} hrs'.format(the_time.hour + the_time.minute/60.0))
This will print:
>>> print('{} hrs'.format(the_time.hour + the_time.minute/60.0)) 6.5 hrs
source share