def to_sec(v):
"""
Convert millisecond, microsecond or nanosecond to second.
ms_to_ts, us_to_ts, ns_to_ts are then deprecated.
"""
v = float(str(v))
if (type(v) != types.FloatType
or v < 0):
raise ValueError('invalid time to convert to second: {v}'.format(v=v))
l = len(str(int(v)))
if l == 10:
return int(v)
elif l == 13:
return int(v / 1000)
elif l == 16:
return int(v / (1000**2))
elif l == 19:
return int(v / (1000**3))
else:
raise ValueError(
'invalid time length, not 10, 13, 16 or 19: {v}'.format(v=v))
评论列表
文章目录