Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
datetime.strftime : "%-d" or "%#d" solution in Clear category for Date and Time Converter by Phil15
"""
Day 1
'%d' --> '01'
'%-d' --> '1' not on windows
'%#d' --> '1' only on windows
'%_d' --> ' 1' not on windows, and it has leading spaces instead.
From what I tested, it works for a lot of "%?":
Years, months, hours (12 or 24-hour clock), weeks, days, minutes, seconds...
"""
from datetime import datetime
def date_time(time_input: str) -> str:
time = datetime.strptime(time_input, '%d.%m.%Y %H:%M')
h, m = 's' * (time.hour != 1), 's' * (time.minute != 1)
try:
return time.strftime(f'%-d %B %-Y year %-H hour{h} %-M minute{m}')
except ValueError:
# On Windows...
return time.strftime(f'%#d %B %#Y year %#H hour{h} %#M minute{m}')
# Years 0... untested, so I suppose it does not want leading zeros either.
Sept. 22, 2020
Comments: