admin管理员组文章数量:1287820
I am using pikaday module for datepicker, but the format es 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
I am using pikaday module for datepicker, but the format es 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
Share Improve this question edited Jul 19, 2016 at 10:53 Rajesh 25k5 gold badges50 silver badges83 bronze badges asked Jul 19, 2016 at 10:50 mizlulmizlul 751 silver badge9 bronze badges 4- github./dbushell/Pikaday – Rayon Commented Jul 19, 2016 at 10:51
- @Rayon i have looked at this link but still I am not able to fix this... Could you tell me more specifically what should I add or modify – mizlul Commented Jul 19, 2016 at 10:55
- Do share a fiddle so that one can play with it.... – Rayon Commented Jul 19, 2016 at 10:55
- also I would be more happy if I would find a datetimepicker not only datepicker, are there any datetimepicker for angularjs 1.2.16, ui-bootstrap 0.12.0 – mizlul Commented Jul 19, 2016 at 10:58
3 Answers
Reset to default 4You 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');
}
});
use moment.js to set the date format:
var picker = new Pikaday(
{
field: document.getElementById('eDate'),
toString(date, format) { // using moment
return moment(date).format('MM/DD/YYYY');
},
});
quick update, if you don't want to use moment.js, you can fdo the following
new Pikaday({
field: document.getElementById('eDate'),
toString: function(date) {
var parts = [('0'+date.getDate()).slice(-2), ('0'+(date.getMonth()+1)).slice(-2), date.getFullYear()];
return parts.join("-");
}
})
this will produce 18-07-1980. You can change from '-' to '/' by changing return parts.join("-"); and you can rearrange parts to apply mm/dd/yyyy via parts array
本文标签: javascripthow do I format date when using pikadayStack Overflow
版权声明:本文标题:javascript - how do I format date when using pikaday - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741317755a2372019.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论