• Post Reply Bookmark Topic Watch Topic
  • New Topic

time  RSS feed

 
hari thatikonda
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi i need the age from user entered Birth day date. how can i get system current time and caliculate his age.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nothing to do with GUI stuff. Moving to Java In General (Intermediate)
 
David Hibbs
Ranch Hand
Posts: 374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@see java.util.calendar.

I'll start you off, but will leave the real work as an exercise for the reader.

String userInput = "09/30/1984"; // Sept 30, 1984
SimpleDateFormat sdf = new SimpleDateFormat(MM/dd/yyyy);
Calendar currentDate = Calendar.getInstance();
Calendar birthDate = Calendar.getInstance();
birthDate.setTime( sdf.parse(userInput) );
// you do the math here, comparing birthDate and currentDate
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!