[英]How to format elapsed time from seconds to hours, minutes, seconds and milliseconds in Python?
[英]How to get milliseconds after midnight with the hours, minutes and seconds we give in the function? (in Python)
如何使用我们在 function 中给出的小时、分钟和秒来获取午夜后的毫秒数? (在 Python 中)
def past(h,m,s):
return ?
请帮我...
像这样
import datetime
def past(h,m,s):
return datetime.timedelta(hours=h, minutes=m, seconds=s).total_seconds()*1000
这会将 timedelta object 转换为秒,然后将其乘以 1000 以获得毫秒。
或者你可以只使用数学
def past(h,m,s):
returns (h*(60**2)+m*60+s)*1000
等于(hours*seconds_in_hour + minutes*seconds_in_minutes + seconds) * millis_in_second
还:
def past(h, m, s):
milsec = s * 1000
sm = (m * 60) * 1000
sh = (h * 3600) * 1000
summilsec = sh + sm + milsec
return summilsec
1 小时 = 3600000 毫秒
1 分钟 = 60000 毫秒
1 秒 = 1000 毫秒
那么方程将是
ms = (h*3600000) + (m*60000) + (s*1000)
这是 function
def past(h,m,s):
return ((h*3600000) + (m*60000) + (s*1000))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.