Given a date string in the form&nbsp;Day Month Year, where:


	Day&nbsp;is in the set {"1st", "2nd", "3rd", "4th", ..., "30th", "31st"}.
	Month&nbsp;is in the set {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}.
	Year&nbsp;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.


&nbsp;
Example 1:

Input: date = "20th Oct 2052"
Output: "2052-10-20"


Example 2:

Input: date = "6th Jun 1933"
Output: "1933-06-06"


Example 3:

Input: date = "26th May 1960"
Output: "1960-05-26"


&nbsp;
Constraints:


	The given dates are guaranteed to be valid, so no error handling is necessary.


class Solution:
    def reformatDate(self, date: str) -> str:

        m_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"}

        day=date[:-11]

        if len(day)==1:
            day="0"+day

        return(date[-4:] + "-" + m_dict_[date[-8:-5]] + "-" + day)
class Solution {
    public String reformatDate(String date) {
        int len = date.length();
        
        String[] monthArray = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
        
        String year = date.substring(len - 4);
        int month = Arrays.asList(monthArray).indexOf(date.substring(len - 8, len - 5)) + 1;
        String day = date.substring(0, len - 11);
        
        StringBuffer sb = new StringBuffer();
        
        sb.append(year + "-");
        
        if(month < 10)
            sb.append("0" + month + "-");
        else
            sb.append(month + "-");
        
        if(day.length() == 1) 
            sb.append("0" + day);
        else
            sb.append(day);
        
        return sb.toString();
    }
}
class Solution {
public:
    string reformatDate(string date) {
        map<string,int>m;
        m["Jan"] =1;
        m["Feb"] =2;
        m["Mar"] =3;
        m["Apr"] =4;
        m["May"] =5;
        m["Jun"] =6;
        m["Jul"] =7;
        m["Aug"] =8;
        m["Sep"] =9;
        m["Oct"] =10;
        m["Nov"] =11;
        m["Dec"] =12;
        string ans;
        for(int i=date.length()-4; i<date.length(); i++){
            ans+=date[i];
        }
        ans += "-";
        string month;
        for(int i=date.length()-8; i<=date.length()-6; i++){
            month+=date[i];
        }

        int yes = m[month];

        if(yes<=9){
            ans += '0';
        }
        ans = ans + to_string(yes);
        ans += "-";
        int i = 0;
        if(date[1]=='t' || date[1]=='s' || date[1]=='n' || date[1]=='r'){
            ans+='0';
            ans+=date[0];
        }
        else{
            ans+=date[0];
            ans+=date[1];
        }
        return ans;
    }
};
var reformatDate = function(date) {
       const ans = [];
       const month = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
        
        const [inputDate,inputMonth,inputYear] = date.split(' ');
        ans.push(inputYear);
        ans.push("-");
    
        const monthIndex = month.findIndex(mon => mon === inputMonth);
        const formatedMonth = String(monthIndex + 1).padStart(2,'0');
        ans.push(formatedMonth);
        ans.push("-");
    
        const slicedDate = inputDate.slice(0,2);
        if(+slicedDate >= 10){
            ans.push(slicedDate);
        }else{
            const formatedDate = inputDate.slice(0,1).padStart(2,'0');
            ans.push(formatedDate)
        }
          
       return ans.join('');
};
Reformat Date