Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 430
TechnoCorner Avatar asked Aug 22 '16 05:08

TechnoCorner


People also ask

Is MomentJS being deprecated?

MomentJs recently announced that the library is now deprecated. This is a big deal for the javascript community who actively downloads moment almost 15 million times a week. With that I began a journey during a Hackathon to replace moment in a core library at my company.

How do I compare two dates in MomentJS?

Compare two dates using Moment. js has a diff() method, which gives the difference between two dates in years, months, days, hours, minutes, seconds, milliseconds, etc. We can use the second unit in our case to find the difference between the two dates.

How do I get time from MomentJS?

You can directly call function momentInstance. valueOf(), it will return numeric value of time similar to date. getTime() in native java script.

How do I get current year in MomentJS?

year() method is used to get or set the year of the Moment object. The year value that can be set has a range from -270,000 to 270,000. Syntax: moment().


1 Answers

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.

like image 140
str Avatar answered Oct 21 '22 17:10

str