function calAge()
{
var curday = $("#curDay").val();
var curmon = $("#curMonth").val();
var curyear = $("#curYear").val();
var calday = $("#calDay").val();
var calmon = $("#calMonth").val();
var calyear = $("#calYear").val();
if (curday == "" || curmon == "" || curyear == "" || calday == "" || calmon == "" || calyear == "")
{
alert("Please fill all the values and click go");
return false;
}
if (parseFloat(calyear) > parseFloat(curyear))
{
alert("Enter your date of birth year less than current year");
return false;
}
if (parseFloat(calyear) == parseFloat(curyear) && parseFloat(calmon) > parseFloat(curmon))
{
alert("Enter your date of birth month less than current month");
return false;
}
if (parseFloat(calyear) == parseFloat(curyear) && parseFloat(calmon) == parseFloat(curmon) && parseFloat(calday) > parseFloat(curday))
{
alert("Enter your date of birth date less than current date");
return false;
}
if (curday == calday && curmon == calmon && curyear == calyear)
{
alert("Happy Birthday...!");
return false;
}
var curd = new Date(curyear, curmon - 1, curday);
var cald = new Date(calyear, calmon - 1, calday);
if (cald.getMonth() != (calmon - 1))
{
alert("Enter your valid date of birth");
return false;
}
if (curd.getMonth() != (curmon - 1))
{
alert("Enter your valid date");
return false;
}
if (curd.getFullYear() < cald.getFullYear())
{
alert("Enter your valid date");
return false;
}
var diff = Date.UTC(curyear, curmon - 1, curday, 0, 0, 0) - Date.UTC(calyear, calmon - 1, calday, 0, 0, 0);
var dife = datediff(cald, curd);
console.log(dife);
$(".your_age").text(dife.years + " years " + dife.months + " months " + dife.days + " days");
var secleft = diff / 1000 / 60;
$(".your_age_min").text(secleft + " minutes");
var hrsleft = secleft / 60;
$(".your_age_hour").text(hrsleft + " hours");
var daysleft = hrsleft / 24;
$(".your_age_days").text(daysleft + " days");
// var secondsleft = secleft * 60;
// $("#r8").val(secondsleft + " seconds");
var as = parseInt(calyear) + dife.years + 1;
var diff = Date.UTC(as, calmon - 1, calday, 0, 0, 0) - Date.UTC(curyear, curmon - 1, curday, 0, 0, 0);
var datee = diff / 1000 / 60 / 60 / 24;
if ((curday == calday) && (curmon == calmon))
{
$(".your_birthday span").html("Happy Birthday");
} else
{
$(".your_birthday span").html(datee + " days left until your next birthday");
}
return true;
}
参考:https ://www.quizexpo.com/how-old-am-i-age-calculator/