#1507

Reformat Date

pupil · 360 · lc easy +23 · verified · 68.3% accepted · 505 likes · top 75%

Description

You are given a date string in the form "Day Month Year", where Day has an ordinal suffix (e.g. "1st", "2nd", "3rd"), Month is a 3-letter abbreviation (e.g. "Jan"), and Year is a 4-digit year. Convert it to the format "YYYY-MM-DD" with zero-padded month and day fields.

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"

Code

1
2
3