I'm using Bootstrap datetimepicker. I need it to format the date as dd/mm/yyyy, not mm/dd/yyyy.
The documentation says this:
format
String. Default: “mm/dd/yyyy”
The date format, combination of d, dd, D, DD, m, mm, M, MM, yy, yyyy.
- d, dd: Numeric date, no leading zero and leading zero, respectively. Eg, 5, 05.
- D, DD: Abbreviated and full weekday names, respectively. Eg, Mon, Monday.
- m, mm: Numeric month, no leading zero and leading zero, respectively. Eg, 7, 07.
- M, MM: Abbreviated and full month names, respectively. Eg, Jan, January
- yy, yyyy: 2- and 4-digit years, respectively. Eg, 12, 2012.
so I have changed this:
$('#datetimepicker6').datetimepicker();
to this:
$('#datetimepicker6').datetimepicker({
format: 'dd/mm/yyyy'
});
However, I am now getting weird input values. Instead of 01/05/2015
, I get Fr/35/yyyy
.
What on earth is going on?
The dd
doing what it said DD
would do was a clue.
I'm not sure why this happened, since it seems to work for others, but I was able to solve it by using DD/MM/YYYY
(contrary to what the documentation says).
$('#datetimepicker6').datetimepicker({
format: 'DD/MM/YYYY'
});
gives this:
and with the hours in:
$('#datetimepicker6').datetimepicker({
format: 'DD/MM/YYYY hh:mm'
});