How to get milliseconds after midnight with the hours, minutes and seconds we give in the function? (in Python)
def past(h,m,s):
return ?
Please Help me…
>Solution :
Like this
import datetime
def past(h,m,s):
return datetime.timedelta(hours=h, minutes=m, seconds=s).total_seconds()*1000
This will convert the timedelta object into seconds and then multiply it by a 1000 to get the milliseconds.
Alternatively you could just use maths
def past(h,m,s):
returns (h*(60**2)+m*60+s)*1000
Which is equal to (hours*seconds_in_hour + minutes*seconds_in_minutes + seconds) * millis_in_second