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)
心有猛虎,细嗅蔷薇