Javascript date objects in different browsers

So we use a tool called dhtmlxscheduler for filling our timetables. It works nice! We just drag and drop the times we want and press save to edit the current weekschedule in PHP.


Internet Explorer had a weird bug where it set all the times to 01:00 – 01:00.
So I started investigating why this could be, and it turned out that the time was send to PHP correctly, but PHP could not interpret the string returned from the date object of IE. The other major browsers seemed to have no issues with this whatsoever..

It turns out the date string outputted in IE was different from other browsers.

The solution was to format the date to a general string before sending it to PHP;

// Format the date to be used in a general way, IE had some issues with this, of course..
var tmpdate = null;
var tmptime = null;
var hours = null;
var minutes = null;
var seconds = null;

tmpdate = $.datepicker.formatDate('yy-mm-dd', eventdata[attribute]);
// Add leading zero's if needed
hours = eventdata[attribute].getHours(); 
if(hours < 10){ hours = "0"+hours; }

minutes = eventdata[attribute].getMinutes(); 
if(minutes < 10){ minutes = "0"+minutes; }

seconds = eventdata[attribute].getSeconds(); 
if(seconds < 10){ seconds = "0"+seconds; }

tmptime = hours+':'+minutes+':'+seconds;
$newHiddenElement.val(tmpdate +' '+ tmptime);

Leave a Reply

Your email address will not be published. Required fields are marked *