Given date-time D, write a program to print the time left for the next New Year.Input
The input will be a single line containing the date-time in the string format similar to "Dec 30 2020 02:43 PM".Output
The output should be a single line containing hours and minutes left for the next new year in the format similar to "33 hours 17 minutes".Explanation
For example, if the given date-time is "Dec 30 2020 02:43 PM", the difference between "Dec 30 2020 02:43 PM" and "Jan 1 2021 00:00 AM" is 1 day 9 hours 17 minutes. The difference in hours and minutes is 1 * 24 + 9 hours and 17 minutes. So the output should be "33 hours 17 minutes".
from datetime import datetime
line = input()
D = datetime.strptime(line, '%b %d %Y %I:%M %p')
NY = datetime(D.year+1, 1, 1)
dt = NY - D
h = dt.days*24 + dt.seconds//3600
m = (dt.seconds // 60) % 60
print(f'{h} houres {m} minutes')
Comments
Leave a comment