python代码片段

输入分钟、秒,输出格式为:  hh:mm:ss

代码实现:

import datetime

def convert_to_hh_mm_ss(minutes, seconds):
    total_seconds = minutes * 60 + seconds
    time_delta = datetime.timedelta(seconds=total_seconds)
    hours = total_seconds // 3600
    minutes = (total_seconds % 3600) // 60
    seconds = total_seconds % 60
    time_str = f"{hours:02d}:{minutes:02d}:{seconds:02d}"
    return time_str

# 示例用法
minutes = 2
seconds = 50
formatted_time = convert_to_hh_mm_ss(minutes, seconds)
print(formatted_time)

 

posted @ 2023-09-12 19:39  何双新  阅读(22)  评论(0编辑  收藏  举报