Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how can i show seconds value ? #221

Open
sonylouis opened this issue Oct 20, 2016 · 1 comment
Open

how can i show seconds value ? #221

sonylouis opened this issue Oct 20, 2016 · 1 comment

Comments

@sonylouis
Copy link

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
Copy link
Owner

ghusse commented Oct 22, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants