js to compare the size of two dates

principle

Convert two dates to Date type, and then get the number of milliseconds for comparison

Code

function tab(date1,date2){
    var oDate1 = new Date(date1);
    var oDate2 = new Date(date2);
    if(oDate1.getTime() > oDate2.getTime()){
        console.log('第一个大');
    } else {
        console.log('第二个大');
    }
}
tab('2015-10-10 12:12:00','2015-10-11 13:10:36');

Guess you like

Origin www.cnblogs.com/pbluesky/p/12685728.html