Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get milliseconds after midnight with the hours, minutes and seconds we give in the function? (in Python)

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…

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading