网站制作学习网Python→正文:Python将秒转换成分钟
字体:

Python将秒转换成分钟

Python 2022/7/25 15:06:39  点击:不统计

%77w%77%2Ef%6F%72p%73%70%2Ec%6E

在时间处理上获取到了秒的数量,怎么转换为小时分钟秒的格式,比如

120秒 = 00:02:00 分钟呢

 

将秒转换为小时分钟代码如下:
 

def trans_seconds_to_time(self,seconds):

    s = seconds % 60;

    m = (seconds - s) % 60

    h = (seconds - m * 60 -s) % 60

    return str(h).zfill(2)+":"+str(m).zfill(2)+":"+str(s).zfill(2)

 

原理很简单,每次都是模除,每次减去上面几次的时间处理综合,然后在模除。


http://www.forasp.cn/

·上一篇:The repository located at mirrors.aliyun.com is not a trusted or secur >>    ·下一篇:Body ('') is not valid Latin-1 >>
推荐文章
最新文章