📌  相关文章
📜  检查是否超过 18 个 javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:01.930000             🧑  作者: Mango

代码示例1
function isOver18(dateOfBirth) {
  // find the date 18 years ago
  const date18YrsAgo = new Date();
  date18YrsAgo.setFullYear(date18YrsAgo.getFullYear() - 18);
  // check if the date of birth is before that date
  return dateOfBirth <= date18YrsAgo;
}

isOver18(new Date("1999-12-01")); // true
isOver18(new Date("2020-03-27")); // false