Home > Article > Web Front-end > How to compare time units in JS
This time I will bring you the method of comparing time units in JS. What are the precautions for comparing time units in JS? The following is a practical case, let’s take a look.
//时间比较(yyyy-MM-dd) function compareDate(startDate, endDate) { var arrStart = startDate.split("-"); var startTime = new Date(arrStart[0], arrStart[1], arrStart[2]); var startTimes = startTime.getTime(); var arrEnd = endDate.split("-"); var endTime = new Date(arrEnd[0], arrEnd[1], arrEnd[2]); var endTimes = endTime.getTime(); if (endTimesI believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to the php Chinese website0) { alert("endTime大于tartTime!"); } else if (thisResult == 0) { alert("endTime等于tartTime!"); } else { return '异常'; } }
Other related articles!
Recommended reading:Summary of experience using JS
!=, ==, !==, === usage summary
The above is the detailed content of How to compare time units in JS. For more information, please follow other related articles on the PHP Chinese website!