/* jqueryui的datepicker的string转日期 [-][+]20[y][m][w][d] 表示偏移多少 利用了new Date()传入不合法参数也能转换的特性 = .= / this.getOffsetDate = function(offset){ var date = new Date(), year = date.getFullYear(), month = date.getMonth(), day = date.getDate(), pattern = /([+-]?[0-9]+)\s(d|D|w|W|m|M|y|Y)?/g, matches = pattern.exec(offset);原文链接:https://www.f2er.com/note/422743.htmlwhile (matches) { switch (matches[2] || “d”) { case “d” : case “D” : day += parseInt(matches[1],10); break; case “w” : case “W” : day += parseInt(matches[1],10) * 7; break; case “m” : case “M” : month += parseInt(matches[1],10); break; case “y”: case “Y” : year += parseInt(matches[1],10); break; } matches = pattern.exec(offset); } return new Date(year, month, day);
}