从 timedelta 转换为分钟 [英] Converts from timedelta into minutes

查看:44
本文介绍了从 timedelta 转换为分钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用变量 current time 和 end_program 来计算剩余的分钟数.

I'm calculating with the variables current time and end_program to get the remaining minutes.

current_time = datetime.timedelta(hours = get_24_hours, minutes = get_24_minutes)
end_program = datetime.timedelta(hours = int(program_hours), minutes = int(program_minutes))
current_program = end_program - current_time

输出:

1:30:00
2:00:00
0:45:00
0:45:00
0:15:00
0:15:00
0:35:00

我想将 timedelta 转换为分钟:

I want to converts the timedelta into minutes:

90
120
45
45
15
15
35

如您所见,timedelta 0:15:00 表示 15 分钟,所以我想将其转换为 15,对于 0:35:00 为 35 分钟我想将其转换为 35,对于 0:45:00 为 45 分钟我想将其转换为 45,但对于 2:00:00 为 2 小时,我想将其转换为 120 为 120 分钟.对于 1:30:00 为 1 小时 30 分钟,我想将其转换为 90 分钟.

As you can see the timedelta 0:15:00 which it means for 15 minutes so I want to convert it to 15, for 0:35:00 as 35 minutes I want to convert it to 35, for 0:45:00 as 45 minutes I want to convert it to 45, but for 2:00:00 as 2 hours I want to convert it to 120 as 120 minutes. For 1:30:00 as 1 hour and 30 minutes I want to convert it to 90 minutes.

如何将 timedelta 转换为分钟?

How I can converts from timedelta into minutes?

推荐答案

您可以将秒转换为分钟:

You can convert the seconds into minutes:

print int(current_program.total_seconds() / 60)

这篇关于从 timedelta 转换为分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆