I have this calendar picker that works fine, it reads the date day I am choosing in the textbox, the only weird thing is that when I choose the date day of 9, it reads "2017-03-9" instead of "2017-03-09". What's wrong here?
JavaScript:
var CalendarTwo;
function onPopupTxtDepartureDateChanged(sender) {
        var txtDeparture = $("#txtDepartureDate");
        var date = new Date(sender.getSelectedDate());
        var textDate = date.getFullYear() + "-" + (date.getMonth() < 9 ? "0" + (date.getMonth() + 1)
            : (date.getMonth() + 1)) + "-" + (date.getDate() < 9 ? "0" + date.getDate() : date.getDate());
        CalendarTwo = sender;
        txtDeparture.val(textDate);
}