how to calculate age from date of birth in java using calendar

Solutions on MaxInterview for how to calculate age from date of birth in java using calendar by the best coders in the world

showing results for - "how to calculate age from date of birth in java using calendar"
Melvin
05 Jul 2019
1package com.candidjava.time;
2
3import java.text.ParseException;
4import java.text.SimpleDateFormat;
5import java.time.LocalDate;
6import java.time.Period;
7import java.util.Calendar;
8import java.util.Date;
9
10public class DobConversion {
11 public static void main(String[] args) throws ParseException {
12  //direct age calculation 
13  LocalDate l = LocalDate.of(1998, 04, 23); //specify year, month, date directly
14  LocalDate now = LocalDate.now(); //gets localDate
15  Period diff = Period.between(l, now); //difference between the dates is calculated
16  System.out.println(diff.getYears() + "years" + diff.getMonths() + "months" + diff.getDays() + "days");
17
18  //using Calendar Object
19  String s = "1994/06/23";
20  SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
21  Date d = sdf.parse(s);
22  Calendar c = Calendar.getInstance();
23  c.setTime(d);
24  int year = c.get(Calendar.YEAR);
25  int month = c.get(Calendar.MONTH) + 1;
26  int date = c.get(Calendar.DATE);
27  LocalDate l1 = LocalDate.of(year, month, date);
28  LocalDate now1 = LocalDate.now();
29  Period diff1 = Period.between(l1, now1);
30  System.out.println("age:" + diff1.getYears() + "years");
31 }
32} 
33
queries leading to this page
get birth date in javajava calculate age in daysjava get age from date of birthhow to find my age in javahow to calculate average age in javahow to display date of birth in javahow to calculate age from date of birth in javacount years from date of birth in javahow to calculate average age javacalculate age using date of birth in javajava calculate age from birthdaycalculate the age from date of birth javadate of birth javajava find age from date of birthcalculate age from date of birth in javajava calculate age with yearjava get age from datehow to calculate a date of birth base in year in javajava calculate agecalculate age in days javaage calculator in javajava date calculation agejava count age from dateget age from java util dateget age by date of birth java 8how to calculate the age from the date of birth in javacalculate age from date birth javajava how to calculate age by date of birthget age by date of birth javacalculate date of birth javahow to convert date of birth into age javacount year from my birth date in javawrite a java program to calculate the age from given date of birthhow to calculate age in java using current datecode for calculating the age from the date of birth is given java program calculate age javafind age using date of birth in javacalculate age from birth year javahow to calculate age from data of birth javajava age calculator date birthcalculate date of birth when age is known javafind age in javaprogram to find age from date of birth in javahow to calculate the age by date of birth from a string javajava calculate age in yearshow to calculate someone 27s age from date of birth javacalculate age from date javahow to calculate age from curent date and birth date in javacalculate age from date of birth in javascalculate age from date of birth javahow to work out age from date of birth javajava calendar get agehow to calculate the age by date of birth javaget age from date javacalculate year of birth in javahow to calculate age from date of birth javajava calculate age with date formatcalculate age in javacheck age using date of birth javadate of birth in javacompute age from date javacalculate age using util date javacalculating current age javaage calculator javaget age from date of birth javajava calculate age from localdatejava create a dob programjava function to calculate age from date of birthcalculate age from string with birth date javahow to calculate ahe from date of birth javahow to calculate age in javacalculate age from date of birth java examplesimple way of calculating age in javajava calculate age from date of birthhow to have a maximum of age from birth date javaread date of birth in javaage in days finder in java java age calculatorcalculate age with java by birth datedate of birth from age javacalculating age in javahow to calcualate age in java given birtdatecalculate age java datecalculate date of birth from age in javahow to get age using birthday in javareturn the age from current date of birth in terms of months in javacalculate age based on date of birth javacalculate age in java with java util datehow to get an age from a date javafind age from date of birth in javajava how oldjava calculate age in yearage using date of birth in javacheck the age using javaage calculate in javahow to compute age using birthday in javaage from birth date in javahow calculate age from a birthdate javafind your age in javaget the age of someone by date of birth in javacurrent age calculator month day year in javasimple age calculator in javahow to calculate age from date of birth in java using calendar