Friday 6 November 2020

Pikaday JS How to use full day and month names for input format without moment js

I'm using Pikaday.js like so:

new Pikaday({
            field: document.getElementById('top-banner-datepicker'),
            minDate: new Date()

I know that the answer lies in this example from the documentation:

var picker = new Pikaday({
    field: document.getElementById('datepicker'),
    format: 'D/M/YYYY',
    toString(date, format) {
        // you should do formatting based on the passed format,
        // but we will just return 'D/M/YYYY' for simplicity
        const day = date.getDate();
        const month = date.getMonth() + 1;
        const year = date.getFullYear();
        return `${day}/${month}/${year}`;
    },
    parse(dateString, format) {
        // dateString is the result of `toString` method
        const parts = dateString.split('/');
        const day = parseInt(parts[0], 10);
        const month = parseInt(parts[1], 10) - 1;
        const year = parseInt(parts[2], 10);
        return new Date(year, month, day);
    }
});

But I can't figure out how to use full day (Monday, Tuesday, Wednesday, etc) and full month names (January, February, etc) instead of the abbreviations (Mon, Tue, Wed... Jan, Feb, Mar... etc)

I don't want to use Moment.JS as it's a giant dependency.

Any help much appreciated!

Thank you

enter image description here



from Pikaday JS How to use full day and month names for input format without moment js

No comments:

Post a Comment