-1

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...

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
sadegh
  • 23
  • 5

2 Answers2

0

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

Marko Borković
  • 1,884
  • 1
  • 7
  • 22
0

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))
Mahmoud Noor
  • 186
  • 12