Is there any way to set the format of ? if no then how can i set date in this field using JavaScript in the default format of
Canadian locale happens to follow the same format, too:
new Date().toLocaleDateString('en-CA')
try this :)
function getDefaultDate(){
var now = new Date();
var day = ("0" + now.getDate()).slice(-2);
var month = ("0" + (now.getMonth() + 1)).slice(-2);
var today = now.getFullYear()+"-"+(month)+"-"+(day) ;
return today;
}
$(document).ready(function(){
$("#dateid").val( getDefaultDate());
});
It's ugly, but it works. :/
var today = new Date().toLocaleString('en-GB').split(' ')[0].split('/').reverse().join('-');
I think this can help
function myFormatDateFunction(date, format) {
...
}
jQuery('input[type="date"]')
.each(function(){
Object.defineProperty(this,'value',{
get: function() {
return myFormatDateFunction(this.valueAsDate, 'dd.mm.yyyy');
},
configurable: true,
enumerable : true
});
});
Please check this https://stackoverflow.com/a/9519493/1074944 and try this way also $('input[type="date"]').datepicker().prop('type','text');
check the demo
I would try jquery and jquery ui to add a nice calendar control that does all the value selecting and formatting for you. simple formatting of an input field isn't enough for demanding users of today's web :)
Have a look at this link