I have this code example:
function compareDate(value: string) {
return isBefore(
parse(value, 'dd-MM-yyyy', new Date()),
sub(new Date(), { days: 1 })
);
}
const test = compareDate('31-12-2020');
在parse()函数中,我需要使用
dd-MM-yyyy
格式,还需要支持dd/MM/yyyy
和dd MM yyyy
格式。我该如何实现?输入的值是用户输入的日期字符串,类型为String,并且可能具有上述的任意一种格式。