programming-examples/js/Date/Write a JavaScript program to calculate age..js
2019-11-15 12:59:38 +01:00

10 lines
303 B
JavaScript

function calculate_age(dob) {
var diff_ms = Date.now() - dob.getTime();
var age_dt = new Date(diff_ms);
return Math.abs(age_dt.getUTCFullYear() - 1970);
}
console.log(calculate_age(new Date(1982, 11, 4)));
console.log(calculate_age(new Date(1962, 1, 1)));