1234567891011121314151617181920212223242526272829303132333435363738394041 |
- import re
- months = [
- "January",
- "February",
- "March",
- "April",
- "May",
- "June",
- "July",
- "August",
- "September",
- "October",
- "November",
- "December"
- ]
- def main():
- while True:
- try:
- entered_date = input("Date: ").strip()
- except Exception:
- continue
- if re.match(r"\d+/\d+/\d+", entered_date):
- month, day, year = map(int, entered_date.split('/'))
- elif re.match(r"\w+ \d{1,2}, \d{4}", entered_date):
- entered_date = entered_date.replace(",", "")
- month, day, year = entered_date.split(' ')
- month = months.index(month) + 1
- day, year = map(int, (day, year))
- else:
- continue
- if month > 12 or day > 31:
- continue
- break
- print(f"{year:04d}-{month:02d}-{day:02d}")
- if __name__ == "__main__":
- main()
|