time - 如何将分钟转换为天、小时和分钟?

标签 time hour minute

我是 Python 的初学者,所以我真的不知道很多术语或任何东西。请问如何将分钟转换为小时和分钟 例如:75 分钟 ->0 天 1 小时 15 分钟

print("Welcome to the Scheduler!")
print("What is your name?")
name = input()
print("How many chocolates are there in the order?")
chocolates = input()
print("How many chocolate cakes are there in the order?")
chocolate_cakes = input()
print("How many chocolate ice creams are in the order?")
chocolate_ice_creams = input()
total_time = float(chocolates) + float(chocolate_cakes) + float(chocolate_ice_creams)
print("Total Time:")
print("How many minutes do you have before the order is due?")
minutes = input()
extra_time = float(minutes) - float(total_time)
print("Your extra time for this order is", extra_time)

time = extra_time // 60

print("Thank you,", name)

最佳答案

好吧,如果您输入的分钟数大于等于 1440 分钟,那么您至少有一天的时间。因此,为了处理这个(以及时间的其他方面),我们可以使用模数 (%)。

days = 0
hours = 0
mins = 0

time = given_number_of_minutes   
days = time / 1440     
leftover_minutes = time % 1440
hours = leftover_minutes / 60
mins = time - (days*1440) - (hours*60)
print(str(days) + " days, " + str(hours) + " hours, " + str(mins) +  " mins. ")

这应该有效。

关于time - 如何将分钟转换为天、小时和分钟?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35004952/

相关文章:

java - 在 Java 中将 JSON 对象转换为 util.Date

java - 时间不会在 Applet 中重新绘制

java - 从 Instant.now() 生成的日期中提取日期、小时和分钟

php - 从分钟正确计算小时

java - 当小时和分钟变量低于零时,moveForward(lostTime) 应如何给出正确的输出?

java - 将分钟数格式化为时间

ruby-on-rails - Ruby 时间和范围(包含/排除)

javascript - 有效地找到落在一定数量范围内的对象

Python:计算 CSV 中每小时的平均值?

MySQL - 在一分钟内枚举所有行并保留第一行