Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to use moment to compare time for calendar change color

var checkTime = function () {
    var hour = $(".hour").text().trim();

    var time = moment(hour, "LT");
    console.log(time)

    //remove any old classes from element
    $(".hour").removeClass(".present .past .future");

    // apply new class if task is near/over due date
    if (moment().isAfter(time)) {
        $(".hour").addClass(".past");
    } else if (moment().isBefore(time)) {
        $(".hour").addClass(".future");
    } else {
        $(".hour").addClass(".present");
    }
}

checkTime();
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #moment #compare #time #calendar #change #color
ADD COMMENT
Topic
Name
1+9 =