toAge method

String toAge()

Implementation

String toAge() {
  DateTime now = DateTime.now();
  DateTime birth = DateTime.parse(this);
  int ageInYears = now.year - birth.year;

  if (now.month < birth.month ||
      (now.month == birth.month && now.day < birth.day)) {
    ageInYears--;
  }

  return "$ageInYears tahun";
}