毫秒级日期求平均值
作者:互联网
import time
import datetime
d = ['00:48:53.786', '00:48:53.859']
t = []
sum_t = 0
for i in d:
# +datatime 的原因是转换出来的时间戳小于系统的初始时间
# 先将日期转换为毫秒级时间戳放到list中
dd = datetime.datetime.strptime(i, '%H:%M:%S.%f') + datetime.timedelta(days=36500)
ts = int(time.mktime(dd.timetuple()) * 1000.0 + (dd.microsecond / 1000.0))
t.append(ts)
for i in t:
# 将时间戳相加求平均值
sum_t = sum_t + int(i)
mean_t = sum_t / len(t)
# 再将时间戳转换为日期
mean_t = datetime.datetime.fromtimestamp(mean_t/1000)
print(mean_t.strftime("%H:%M:%S.%f"))
标签:00,平均值,int,sum,datetime,毫秒,日期,dd,mean 来源: https://www.cnblogs.com/cokefentas/p/16371296.html