Wednesday, October 14, 2015

Compare Time using Javascript

Some time we need to compare two time for our development. In  JS it is difficult. In this topics I discus on how to compare two time. For this I create a JS function named timecompare. Here we passed tow parameter for this function named startTime and endTime. This function return TRUE only when second parameter (time) larger then first one

function timecompare(startTime,endTime){
    var regExp = /(\d{1,2})\:(\d{1,2})\:(\d{1,2})/;
    if(parseInt(endTime .replace(regExp, "$1$2$3")) > parseInt(startTime .replace(regExp, "$1$2$3"))){
    return true;
        return false;
timecompare('14:01:20','22:00:00'); // Output : TRUE
timecompare('10:01:20','2:00:00'); // Output : FALSE


Post a Comment


Copyright @ 2014 Tech Tutorial .