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...
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...
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
1 hour = 3600000 ms
1 minute = 60000 ms
1 second = 1000 ms
then the equation would be
ms = (h*3600000) + (m*60000) + (s*1000)
here is the function
def past(h,m,s):
return ((h*3600000) + (m*60000) + (s*1000))