根据出生日期算出年龄

GG_lyf

关注

阅读 71

2022-02-22

根据出生日期换算年龄

getDate() {
	  // this.value = 2001-05-17  出生日期
      var birthdays = new Date(this.value.replace(/-/g, "/"));
      console.log(‘生日转换时间’,birthdays);
      let d = new Date();
      this.age = d.getFullYear() - birthdays.getFullYear() - (d.getMonth() < birthdays.getMonth() || (d.getMonth() == birthdays.getMonth() && d.getDate() < birthdays.getDate()) ? 1 : 0);
      console.log('年龄', this.age)
    }

相关推荐

精彩评论(0)

0 0 举报