python时间格式转换--秒 转换为 时分秒格式

方法一:

 

def seconds_to_hms(seconds_num):
    """
    输入秒数 转换为 时分秒输出
    param: seconds_num integer 666
    return: hms str 00:00:00
    """
    m, s = divmod(seconds_num, 60)
    h, m = divmod(m, 60)
    hms = "%02d:%02d:%02d" % (h, m, s)
    return hms

#divmod() 函数求出两个整数的商和余数
#divmod(a,b) 函数的作用返回一个包含商和余数的元组(a // b, a % b),

方法二:strftime('%H:%M:%S',gmtime(x))

df['时长'].map(lambda x:strftime('%H:%M:%S',gmtime(x)))

 

posted @ 2022-04-12 22:58  白云~  阅读(2405)  评论(0编辑  收藏  举报