Given a date string in the form Day Month Year, where:
Day is in the set {"1st", "2nd", "3rd", "4th", ..., "30th", "31st"}. Month is in the set {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}. Year is in the range [1900, 2100]. Convert the date string to the format YYYY-MM-DD, where:
YYYY denotes the 4 digit year. MM denotes the 2 digit month. DD denotes the 2 digit day.
class Solution:
def reformatDate(self, date: str) -> str:
arr = date.split(" ")
store = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
arr[1] = str(store.index(arr[1]) + 1)
if len(arr[1]) < 2:
arr[1] = "0" + arr[1]
if len(arr[0]) == 4:
arr[0] = arr[0][:2]
elif len(arr[0]) == 3:
arr[0] = arr[0][:1]
if len(arr[0]) < 2:
arr[0] = "0" + arr[0]
arr.reverse()
ans = "-".join(arr)
return ans