1、带有字符串的时间去掉-改成/ 以及去掉时分秒 如“2022-02-05 05:06:05”
// 去除时间的格式以及去掉时分秒
const getdata = function (data: any) {
const gets = /\d{4}-\d{1,2}-\d{1,2}/g.exec(data)?.toString();
const ss = gets?.replaceAll('-', '/');
return ss;
};
2、时间的对比 带有字符串的 如“2022-02-05 05:06:05” 可以对比
if (new Date('2022-02-05 05:06:05').getTime() > new Date('2022-02-04 05:06:05').getTime()) {
return true;
} else {
return false;
}
3、如格式为 “ Wed Jun 22 2022 11:17:45 GMT+0800 (中国标准时间)”格式 的对比
if (new Date(new Date(formState.selectStartTime).toLocaleString()).getTime() >
new Date(new Date(formState.selectEndTime).toLocaleString()).getTime()
) {
message.error('开始时间不能大于结束时间!');
return;
}
4、格式为如格式为 “ Wed Jun 22 2022 11:17:45 GMT+0800 (中国标准时间)”格式转为 如“2022-02-05 05:06:05”的格式时间字符串
new Date(formState.selectStartTime).toLocaleString()