How to quickly compare the size of two dates?

            let time = {
                endDate: "2019-02-23",
                endTime: "17:00:35",
                startDate: "2019-02-23",
                startTime: "17:50:35"
            };
            endDate+endTimestartDate+startTime
            
Jul.10,2022

is stitched into a string format and fixed for direct comparison. There is no need to turn the timestamp.


let time = {
    endDate: "2019-02-23",
    endTime: "17:00:35",
    startDate: "2019-02-23",
    startTime: "17:50:35"
};
// 
+new Date(time.endDate+time.endTime) < +new Date(time.startDate+time.startTime);
// `utils`
// :
export const compareDate = (date1, date2) => {
    return new Date(date1).getTime() >= (new Date(date2).getTime());
};

'2019-02-02 17 false < / false >
string comparison will be compared one by one with the Unicode value
first of all, make sure that the length or format of the two characters are the same: ' 22'>'3' / / false

Menu