Reformat Date

This problem can be solved using Python’s built-in datetime library to handle date conversion. You need to create a date string with the correct format and convert it to the desired format.

Here is the Python code for this problem:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Solution:
    def reformatDate(self, date: str) -> str:
        from datetime import datetime

        # Define the month dictionary
        month_dict = {"Jan": '01', "Feb": '02', "Mar": '03', "Apr": '04', 
                      "May": '05', "Jun": '06', "Jul": '07', "Aug": '08', 
                      "Sep": '09', "Oct": '10', "Nov": '11', "Dec": '12'}

        # Split the input date
        day, month, year = date.split()

        # Remove the suffix from day
        day = day[:-2]
        # If the day is single digit, add a leading zero
        if len(day) == 1:
            day = '0' + day

        # Get the month number from the dictionary
        month = month_dict[month]

        # Return the reformatted date
        return f'{year}-{month}-{day}'

This code works by first creating a dictionary to map month names to their respective number representations. The input date is then split into day, month, and year components. The day component has its suffix removed and is padded with a leading zero if necessary. The month component is replaced with its corresponding number using the dictionary. Finally, the reformatted date is returned in the ‘YYYY-MM-DD’ format.