0
点赞
收藏
分享

微信扫一扫

根据出生日期算出年龄

GG_lyf 2022-02-22 阅读 67

根据出生日期换算年龄

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 条评论