Home - Date and Time Converter
My code (I know, it sucks. It's my firt shot):
import datetime
def date_time(time: str) -> str:
#day
out = time[0].strip("0") + time[1]
#month and year
month_name = datetime.datetime.strptime(time[3:5], "%m").strftime("%B")
out = out + " " + month_name + " " + time[6:10] + " year "
#time
if time[11:13] == "01":
out = out + " 1 hour "
else:
out = out + time[11].strip("0") + time[12] + " hours "
if time[14:16] == "01":
out = out + "1 minute"
else:
out = out + time[14].strip("0") + time[15] + " minutes"
return out
After checking:
Your result:"11 April 1812 year 1 hour 1 minute"
Right result:"11 April 1812 year 1 hour 1 minute"
Arent the same thing?
Created at: 2021/11/04 16:57; Updated at: 2021/11/04 18:02
The question is resolved.