Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
strptime, strftime and f-string solution in Clear category for Date and Time Converter by kkkkk
from datetime import datetime
def date_time(time: str) -> str:
"""Convert time string to a different format."""
date_obj = datetime.strptime(time, "%d.%m.%Y %H:%M")
month_year = date_obj.strftime("%B %Y year")
# datetime only has options for padded dates and times, so
# normal formatting must be used for those fields.
plural_hour = "" if date_obj.hour == 1 else "s"
plural_minute = "" if date_obj.minute == 1 else "s"
return (f'{date_obj.day} {month_year} {date_obj.hour} hour{plural_hour} '
f'{date_obj.minute} minute{plural_minute}')
Jan. 2, 2020