timeutil.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:pykit 作者: baishancloud 项目源码 文件源码
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))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号