0

我想在 JavaScript 中计算出生日期和系统日期之间的差异。

在 JSP 和 JavaScript 中:

'出生日期 '

function currentAge(DateOfBirth){
    //alert(DateOfBirth);
    var date1 = DateOfBirth;
    date1 = document.getElementById("dateOfBirth").value;
    alert(date1);
    var date2 = new Date();
    alert(date2);

    // _Diff=Math.ceil((date2.getTime()-date1.getTime())/(one_day));

    /* var timeDiff = Math.abs(date2.getTime() - date1.getTime());
    var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));
    //var diffDays = date2.getDate() - date1.getDate();  */
    //alert(_Diff);
}
4

2 回答 2

0
function dateDiff(dateform) {
date1 = new Date();
date2 = new Date();
diff  = new Date();

date1temp = new Date(dateform.firstdate.value);
date1.setTime(date1temp.getTime());

date2temp = new Date(dateform.seconddate.value);
date2.setTime(date2temp.getTime());
diff.setTime(Math.abs(date1.getTime() - date2.getTime()));

timediff = diff.getTime();
days = Math.floor(timediff / (1000 * 60 * 60 * 24)); 
dateform.difference.value = days;
return false; 
}
于 2013-06-12T07:24:11.140 回答
0

现在很好

    function currentAge(DateOfBirth){
        var date1 = document.getElementById("dateOfBirth").value;
           alert(date1);

           var date11=new Date(date1);

           alert(date11);

           var date2 = new Date();
           alert(date2);
           alert(3);
           var timeDiff = Math.abs(date2.getYear() - date11.getYear());

           alert(timeDiff);




     }
于 2013-06-13T03:12:01.560 回答