how do I format date when using pikaday

Issue

I am using pikaday module for datepicker, but the format comes as inappropriate format. I tried adding this line of code but still not working:

.config(['pikadayConfigProvider', function (pikaday) {
    pikaday.setConfig({
        numberOfMonths: 1,
        format: "YYYY/MM/DD"
    });
}]) 

This is how my html looks like:

<div class="modal-body">
  <form role="form">
    <div class="form-group">
      <input type="text" class="form-control" pikaday="myPickerObject" name="time" ng-model="clas.class_.time" placeholder="Enter time" tabindex="3">
    </div>
  </form>
</div>

Also tried to add as an inline attribute

format = “yyyy/mm/dd”

still not working.

Any help

Solution

You can use moment.js and set the format by setting

defaultDate : moment().format("MMM YYYY")

this will be the initial input date display format.
For displaying/processing the date in other desired formats, use

var field = document.getElementById('datepicker');
var picker = new Pikaday({
onSelect: function(date) {
    field.value = this.getMoment().format('Do MMMM YYYY');
    }
});

Answered By – Pratikshya

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published