HTMLify
LeetCode - Reformat Date - Python
Views: 318 | Author: abh
1 2 3 4 5 6 7 8 9 10 11 12 13 | class Solution: def reformatDate(self, date: str) -> str: days = [ "1st", "2nd", "3rd", "4th", "5th", "6th", "7th", "8th", "9th", "10th", "11th", "12th", "13th", "14th", "15th", "16th", "17th", "18th", "19th", "20th", "21st", "22nd", "23rd", "24th", "25th", "26th", "27th", "28th", "29th", "30th", "31st" ] months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] d, m, y = date.split(" ") dd = days.index(d) + 1 mm = months.index(m) + 1 return f"{y}-{mm:02d}-{dd:02d}" |