Since the string you're using isn't in a format recognized by Date.parse()
(more on that here ), you need to manually create that Date object.(由于您使用的字符串不是被识别的格式Date.parse()
(更多的在这里 ),您需要手动创建一个Date对象。)
For example:(例如:)
const strDate = '30.11.2019'; let [d,m,y] = strDate.split(/\D/); const date = new Date(y, --m, d); console.log(date.getFullYear())
You can then use Date.getFullYear()
to get the year and extract the last two digits, as you need.(然后,您可以根据需要使用Date.getFullYear()
获取年份并提取最后两位数字。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…