慕妹3146593
这就是我想出的 - 没有图书馆:var dateString = "Monday 21st September 2020";var dayOfMonth, month, year;[, dayOfMonth, month, year] = dateString.split(" ");var date = new Date([dayOfMonth.match(/\d*/)[0], month, year]);console.log("date:\n" + date);这个想法是使用析构函数将日期字符串分成 4 个部分,并忽略第一个(星期几)。使用正则表达式从月份中的第几天(使用 st/nd/rd/th)提取数字。把事情放回一个新的日期。并作为一个功能:function dateStringToDate(dateString) { var dayOfMonth, month, year; [, dayOfMonth, month, year] = dateString.split(" "); return new Date([dayOfMonth.match(/\d*/)[0], month, year]);}var dates = [ "Monday 21st September 2020", "Erich_Kästner 35th May 1931", "Someday 2nd October 1967"];for(var d = 0; d < dates.length; d++) { console.log(dates[d]+":\n" + dateStringToDate(dates[d]));}.as-console-wrapper { max-height: 100% !important; top: 0; }