Untitled

 avatar
unknown
python
3 years ago
483 B
4
Indexable
def reformatDate(date):
    from calendar import month_abbr
    months, date = {month: i for i, month in enumerate(month_abbr)}, date.split()
	# need to prefix "0" for "1st, 2nd, 3rd, ..., 9th"
	# since "True" in python can implicitly be int(1), we can control the prefixed "0" by len() < 4
    d = "0" * (len(date[0]) < 4) + date[0][:-2]
	# need to prefix 0 if month[date[1]] < 10
    m = "".join(map(str, divmod(months[date[1]], 10)))
    y = date[2]
    return "-".join((y, m, d))
Editor is loading...