栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python将秒换成天时分秒

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python将秒换成天时分秒

def lastTime(t):
    s = ""
    days_s = ""
    hour_s = ""
    min_s = ""
    sec = t


    while True:
        if sec <= 60:
            second_s =str(sec)
            if days_s != "":
                s = days_s +"天"
            if hour_s != "":
                s =s+ hour_s +"小时"
            if min_s != "":
                s =s+ min_s +"分钟"
            s = s + second_s +"秒"
            return s
        if sec >= 60 and sec<3600:
            minutes = sec // 60
            min_s =str(minutes)
            if sec % 60 ==0:
                if days_s != "":
                    s = days_s +"天"
                if hour_s != "":
                    s =s+ hour_s +"小时"
                if min_s != "":
                    s =s+ min_s +"分钟"
                return s
            else:
                sec = sec % 60
        if sec >= 3600 and sec<86400:
            # global sec, hour_s
            hours = sec // 3600
            hour_s = str(hours)

            if sec % 3600 ==0:

                if days_s != "":
                    s = days_s + "天"
                if hour_s != "":
                    s = s + hour_s + "小时"
                return s
            else:
                sec = sec % 3600
        if sec >= 86400:
            days = sec // 86400
            days_s = str(days)
            if sec % 86400 ==0:

                return days
            else:
                sec = sec % 86400
            # print('The number of minutes is {0:.2f}'.format(days))



print(lastTime(24*3600+67+3*3600))

运行

F:pyinstaller-g2venvScriptspython.exe F:/pyinstaller-g2/stf.py
1天3小时1分钟7秒

Process finished with exit code 0

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1033780.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号