i want to calculate age throgh a java class but i have no idea how to that. can anybody please help me!
i want to do following things...
A.
input : Date of Birth - 13.08.1979 [dd/mm/yyyy]
output : age on Current Date (System Date) - 31 year(s) 7 month(s) 1 day(s)
B.
input : Date of birth - 13.08.1979 [dd/mm/yyyy]
input : in which date you want to calculate your age? - 13.08.2011 [dd/mm/yyyy]
output : your age on 13.08.2011 is : 32 year(s) 0 Month(s) 0 day(s)
4 replies to this topic
#1
Posted 14 March 2011 - 06:21 AM
|
|
|
#2
Posted 14 March 2011 - 06:55 AM
Post some code and we will help you.
But the full code will not be given on a silver platter...
The pseudo code will be something like:
Get the user input.
use a tokenizer to split the string into 3 parts.
get todays date.
todaysdate - userdate.
output what you calculate
But the full code will not be given on a silver platter...
The pseudo code will be something like:
Get the user input.
use a tokenizer to split the string into 3 parts.
get todays date.
todaysdate - userdate.
output what you calculate
#3
Posted 14 March 2011 - 02:17 PM
@lintwurm
Could you give a quick explanation of what a tokenizer is?
Also, what would you do if you entered a date that was different than the current time?
Could you give a quick explanation of what a tokenizer is?
Also, what would you do if you entered a date that was different than the current time?
#4
Posted 16 March 2011 - 12:59 AM
You don't even need to use a tokenizer... You can just use the .split() method to split the string into 3 parts.
for instance:
String[] bla = userInput.split("/");
As far as I remember
bla[0] will now be the dd part
bla[1] will be the mm part
and bla[2] will be the yyyy part.
You can use the systems date method to get the current age.
you can try this:
Date date = new Date();
// Keep the MM upper case
DateFormat df = new SimpleDateFormat("dd-MM-yyyy");
String formattedDate = df.format(date);
That should give you the date in the format you want...
And that is if I remember correctly.
Hope that helps
for instance:
String[] bla = userInput.split("/");
As far as I remember
bla[0] will now be the dd part
bla[1] will be the mm part
and bla[2] will be the yyyy part.
You can use the systems date method to get the current age.
you can try this:
Date date = new Date();
// Keep the MM upper case
DateFormat df = new SimpleDateFormat("dd-MM-yyyy");
String formattedDate = df.format(date);
That should give you the date in the format you want...
And that is if I remember correctly.
Hope that helps
#5
Posted 02 May 2011 - 09:21 AM
thanks to all
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









