小编Wil*_*ver的帖子

如何在python 3.x中将秒转换为hh:mm:ss

我只需要数学运算符就可以做到这一点,但是我总是在领域中得到高得离谱的数字。

def main():
seconds = int(input('Seconds to be converted? '))
days = seconds / 86400
seconds = seconds - (days * 86400)
hours = seconds / 3600
seconds = seconds - (hours * 3600)
minutes = seconds / 60
seconds = seconds - (minutes * 60)

print('-------------')
print('You entered: ', seconds)
print('')
print('The converted time is: ', format(days, '1.0f'), ':', format(hours, '1.0f'), ':', format(minutes, '1.0f'), ':', format(seconds, '1.0f'))
Run Code Online (Sandbox Code Playgroud)

python-3.x

-2
推荐指数
2
解决办法
5400
查看次数

标签 统计

python-3.x ×1