JS判断字符串是否符合日期格式

var str='2022-02-20 20:05'
if(/^\d{4}-\d{2}-\d{2}$/.test(str)){
  alert("格式正确!");
}else{
    alert('格式错误')
}