What worked for me was to use the builtin jqueryui function formatDate();
When it comes to the css I had to tweak it a little and add extra classes to be able to highlight dates.
style.css
#datepicker .event-highlight .ui-state-highlight,
.ui-widget-content .ui-state-highlight,
.ui-widget-header .ui-state-highlight
{
background-color: darkgreen !important;
color : white !important;
border: 1px solid darkgreen !important;
border-color: darkgreen !important;
}
jquery formatDate()
//different date formats accepted
"mm/dd/yy"
"yy-mm-dd"
"d M, y"
"d MM, y"
"DD, d MM, yy"
"'day' d 'of' MM 'in the year' yy"
//return today's date
$.datepicker.formatDate("yy-mm-dd", $('#datepicker').datepicker("getDate"));
//alternatively you can use this syntax
jQuery.datepicker.formatDate('yy-mm-dd', 'getDate');
highlight dates in datepicker
$('#datepicker').datepicker({
dateFormat: 'yy-mm-dd',
changeMonth: true,
changeYear: true,
beforeShowDay : function (date){
json.events.forEach(function (jsondate,counter) {
//get jquery date
var jquerydate = $.datepicker.formatDate("yy-mm-dd", date);
//OR alternative syntax
var jquerydate = jQuery.datepicker.formatDate('yy-mm-dd', date);
//get date busy with events
var busyday = jsondate.date;
if (jquerydate === busyday) {
return [true, '.event-highlight', 'tooltip text'];
}else{
return [true, '', ''];
}
});
return [true];
},