ghusse / jQRangeSlider

A jquery UI range selection slider that supports dates
http://ghusse.github.com/jQRangeSlider/
GNU General Public License v3.0
671 stars 147 forks source link

how can i show seconds value ? #221

Open sonylouis opened 8 years ago

sonylouis commented 8 years ago

i used this script : `var min2 = new Date("2014-01-01 00:00:00"), max2 = new Date("2014-01-02 00:00:00");

    function addZero(val) {
        if (val < 10) {
            return "0" + val;
        }
        return val;
    }
    $("#slider2").dateRangeSlider({
        bounds: {
            "min": min2,
            "max": max2
        },
        range: {
            min: {
                minutes: 1
            }
        },
        scales: [
            //primary
            {
                first: function(val) {
                    return val;
                },
                next: function(val) {
                    var next = new Date(val);
                    return new Date(next.setMinutes(val.getMinutes() + 30));
                },
                stop: function(val) {
                    return false;
                },
                label: function(val) {
                    return addZero(val.getHours()) + ':' + addZero(val.getMinutes());
                },
                format: function(tickContainer, tickStart, tickEnd) {
                    tickContainer.addClass("myCustomClass");
                }
            },
            //secondary
            {
                first: function(val) {
                    return val;
                },
                next: function(val) {
                    var next = new Date(val);
                    return new Date(next.setMinutes(val.getMinutes() + 1));
                },
                stop: function(val) {
                    return false;
                },
                label: function(val) {
                    return "";
                },
                format: function(tickContainer, tickStart, tickEnd) {
                }
            }
        ],
        formatter: function(val) {
            var h = val.getHours(),
                m = val.getMinutes();
            return addZero(h) + ':' + addZero(m);
        },
        defaultValues: {
            min: new Date("2014-01-01 00:00:00"),
            max: new Date("2014-01-01 00:00:50")
        }
    });`

but how if i want to add seconds label ? thx

ghusse commented 8 years ago

Hello,

Just change the formatter function to display seconds. You get a Date object, on which you can call getSeconds() to get the number of seconds