Pickadate - how to actually use selected date?

j_d picture j_d · Sep 23, 2015 · Viewed 9.7k times · Source

I'm implementing a pickadate date picker, and it's not clear in the docs how to actually use the date a user selects. Eg I have this written:

$('.datepicker').pickadate({
    onSet: function(context) {
        console.log(context);
    }
});

This produces a weird output (for Sep 8 2015):

Object {select: 1441666800000}

How is this output actually usable?

Answer

Alexandr Lazarev picture Alexandr Lazarev · Sep 23, 2015

Your output is a javascript object, with a property select. Value of this property is a timestamp. Actually this timestamp is amount of milliseconds from the start of unix epoch to the selected day. You can transform in into a date object by using Date.prototype:

$('.datepicker').pickadate({
    onSet: function(context) {
        console.log(new Date(context.select););
    }
});