I'm using bootstrap datepicker on a textbox. The default format of the date when you select a date is mm/dd/yyyy. Now I want to change it to dd/mm/yyyy. How can I accomplish this. Right now I'm just initializing it just like this.
$('.datepicker').datepicker()
What should I add to change its format?
This question is related to
twitter-bootstrap
datepicker
$(function () {
$('.datetimepicker').datetimepicker(
{
format: 'Y-m-d h:m:s'
}
);
});`
If by ID:
$('#datepicker').datepicker({
format: 'dd/mm/yyyy'
});
If by Class:
$('.datepicker').datepicker({
format: 'dd/mm/yyyy'
});
this works for me
Open the file bootstrap-datepicker.js
Go to line 1399 and find format: 'mm/dd/yyyy'
.
Now you can change the date format here.
for me with bootstrap 4 datetime picker (http://www.eyecon.ro/bootstrap-datepicker/) format worked only with upper case:
$('.datepicker').datetimepicker({
format: 'DD/MM/YYYY'
});
Easy way:
Open the file bootstrap-datepicker.js
Go to line 1399 and find format: 'mm/dd/yyyy'
.
Now you can change the date format here.
If you are using new jqueryui above code will not help you use this
$('.datepicker').datepicker({dateFormat:"yy-mm-dd"});
As of 2016 I used datetimepicker like this:
$(function () {
$('#date_box').datetimepicker({
format: 'YYYY-MM-DD hh:mm'
});
});
File name : bootstrap-datepicker.js
Line No : 41:
this.format = DPGlobal.parseFormat(options.format||this.element.data('date-format')||dates[this.language].format||'mm/dd/yyyy');
I am using Bootstrap v3.3.4 and using the code:
$('.datepicker').datepicker({
dateFormat: 'dd-mm-yy'
});
Output is: 16-07-2015
Note: only need "yy" for full year.
Source: Stackoverflow.com