Я работаю над вычислениями различий между двумя датами и временем ввода и возврата с помощью appendChild. Проверено на Chrome, Firefox, IE, работает нормально. Но на мобильный возврат NaN.
//...append
$(document).ready(function() {
//...set default date
$('#d1, #d2, #t1, #t2').on('change', function(ev) {
var dl = document.getElementById("diff");
while (dl.hasChildNodes()) {
dl.removeChild(dl.lastChild);
}
//calculation differences between two date and time
var date1 = new Date($('#d1').val() + " " + $('#t1').val()).getTime();
var date2 = new Date($('#d2').val() + " " + $('#t2').val()).getTime();
append(dl, "Interval ", " from: " + $('#d1').val() + " " + $('#t1').val() + " to: " + $('#d2').val() + " " + $('#t2').val()); //return ok
var msec = date2 - date1;
var mins = Math.floor(msec / 60000);
var hrs = Math.floor(mins / 60);
var days = Math.floor(hrs / 24);
var yrs = Math.floor(days / 365);
append(dl, "In minutes: ", mins + " minutes"); //return NaN
mins = mins % 60;
append(dl, "In hours: ", hrs + " hours, " + mins + " minutes"); //return NaN
hrs = hrs % 24;
append(dl, "In days: ", days + " days, " + hrs + " hours, " + mins + " minutes"); //return NaN
days = days % 365;
append(dl, "In years: ", yrs + " years " + days + " days "); //return NaN
});
// trigger change
$('#d1').change();
});
скрипка: https://jsfiddle.net/user2314737/jr5jkv1p/