The simple implementation to parse 'day/month/year HH:MM:SS' datetime format shows as below:
$('#dt').datetimebox({
formatter:function(date){
var s1 = [date.getDate(),date.getMonth()+1,date.getFullYear()].join('/');
var s2 = [date.getHours(),date.getMinutes(),date.getSeconds()].join(':');
return s1 + ' ' + s2;
},
parser:function(s){
if (!s){return new Date();}
var dt = s.split(' ');
var date = new Date(dt[0][2],dt[0][1],dt[0][0]);
if (dt.length>1){
date.setHours(dt[1][0]);
date.setMinutes(dt[1][1]);
date.setSeconds(dt[1][2]);
}
return date;
}
})
Thanks so much for the answer! It helped a lot!
I would like to add a little fix to the code above because it didnt work right away
In the parser there should be another 2 splits and the parser should look like this:
parser:function(s){
if (!s){return new Date();}
var dt = s.split(' ');
var dateFormat = dt[0].split('/');
var timeFormat = dt[1].split(':');
var date = new Date(dateFormat[2],dateFormat[1],dateFormat[0]);
if (dt.length>1){
date.setHours(timeFormat[0]);
date.setMinutes(timeFormat[1]);
date.setSeconds(timeFormat[2]);
}
return date;
}
Then everything works just fine!
Thanks.