TechnoCorner
TechnoCorner

Reputation: 5135

MomentJS from 00:00 to 23:59

I've been trying to add this slider: http://ionden.com/a/plugins/ion.rangeSlider/demo_advanced.html

This is my sample code:

$("#range").ionRangeSlider({
    min: +moment().subtract(12, "hours").format("X"), //need to change to 00:00
    max: +moment().format("X"), //need to change this to 23:59
    from: +moment().subtract(6, "hours").format("X"), 
    grid: true,
    force_edges: true,
    prettify: function (num) {
        var m = moment(num, "X").locale("en");
        return m.format("HH:mm");
    }
});

I would like to add min to 00:00 and max to 23:59

I tried doing

moment("1234", "hmm").format("HH:mm")

I'm getting either invalid date or NaN.

Please help me. I'm not sure where I'm going wrong.

Upvotes: 8

Views: 11761

Answers (1)

str
str

Reputation: 44969

A moment object is a datetime, you cannot just add a time only. Instead create the object and change the time:

min: +moment().startOf("day").format("X"),
max: +moment().endOf("day").format("X"),

Then the prettify callback will only show the time in the slider.

Upvotes: 15

Related Questions