У меня есть 2 текстовых поля. Одно текстовое поле будет принимать дату рождения от пользователя и в зависимости от даты рождения. Я хочу рассчитать и отобразить их возраст в другом текстовом поле.Как рассчитать возраст от даты рождения в Angular 2 с помощью TypeScript
Вот мой компонент класса
Student.component.html
<div class="row">
<div class="input-field col m2">
<input type="date" id="txtdate">
</div>
<div class="input-field col m4">
<input type="number" id="age">
</div>
student.component.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'stud',
templateUrl: './student.component.html'
})
export class StudentComponent implements OnInit
{
constructor() { }
ngOnInit() { }
}
function CalculateAge()
{
var birthdate = <HTMLElement>document.getElementById("txtdate");
var dt = new Date();
var today = dt.getDate();
}
Как я Calculat возраст от даты рождения?
попробуйте использовать valueOf: разница переменная = today.valueOf() - birthdate.valueOf(); – darron614