| | |
trying to do a date of birth comparison.
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Mar 2006
Posts: 2
Reputation:
Solved Threads: 0
I am trying to write a date of birth compair. here is how i have started out but I am not getting the results I want to see I am wanting to enter the text as
03/14/73 and compaire that to todays date and tell the user how old they are in only years.
This is as far as I can get with it and I will be totaly truthfull I did not write the hole thing this is the beginging of a class assinment and I cant find were on the net to get help. Sugestions. Please.
03/14/73 and compaire that to todays date and tell the user how old they are in only years.
This is as far as I can get with it and I will be totaly truthfull I did not write the hole thing this is the beginging of a class assinment and I cant find were on the net to get help. Sugestions. Please.
Java Syntax (Toggle Plain Text)
System.out.print("Enter the year you were born: "); usrYear = getYear(year); userYr = Integer.parseInt(usrYear); System.out.print("Enter the month you were born: "); usrMonth = getMonth(); userMth = Integer.parseInt(usrMonth); System.out.print("Enter the day you were born: "); usrDay = getDay(userMth); userDay = Integer.parseInt(usrDay); System.out.println("Your birthday is on " + userMth + "/" + userDay + "/" + userYr); displayAge(userYr, year, userMth, month, userDay, day); } public static String getYear(int yr)throws Exception { int outYear=0; int year; year = yr; String usrYear = new String(); String output = new String(); usrYear = getString();
hi,
here is a simple program that gives you your age month and day...give the date of birth as an argument though...
here is a simple program that gives you your age month and day...give the date of birth as an argument though...
Java Syntax (Toggle Plain Text)
import java.util.Calendar; import java.util.Date; import java.util.Locale; import java.text.SimpleDateFormat; import java.text.ParseException; public class Age { public Age(long birthday) { Calendar age = Calendar.getInstance(Locale.getDefault()); age.setTimeInMillis(Math.abs(birthday-System.currentTimeMillis())); System.out.println("Your are "+(age.get(Calendar.YEAR)-1970)+" years, "+age.get(Calendar.MONTH)+" month, "+age.get(Calendar.DAY_OF_MONTH)+" days "+(System.currentTimeMillis()-birthday<0 ?"Not Born Yet" :"Old")+"."); } public static void main(String[] args) { SimpleDateFormat dateFormatter = new SimpleDateFormat("dd/MM/yyyy"); if (args.length==0) { System.out.println("Usage:\n java Age dd/mm/yyyy\nWhere:\n dd - date\n mm - month\n yyyy - year"); } else { try { final Date birthday = dateFormatter.parse(args[0]); System.out.println("Your birthday is " + dateFormatter.format(birthday)); final Age myAge = new Age(birthday.getTime()); } catch (ParseException e) { System.out.println("Error parsing your birthday."); e.printStackTrace(); } } } }
![]() |
Similar Threads
- calculating the date of birth (PHP)
- Date of Birth field need help (ASP.NET)
- Submit Button Help (JavaScript / DHTML / AJAX)
- Multiple data being read in (C++)
- Need Help with ArrayList sorting (Java)
Other Threads in the Java Forum
- Previous Thread: Help with input/output in classes
- Next Thread: Pls Help JAVA Program Headaches Not Giving me the right output for user input
| Thread Tools | Search this Thread |
addball android api applet application apps array arrays automation binary bluetooth businessintelligence button card chat class classes client code collision component crashcourse css database draw eclipse ee error event exception fractal free game gis givemetehcodez graphics gui html ide image input integer integration j2me java javadoc javafx javaprojects jni jpanel julia jvm key linux list loan loop machine map method methods migrate mobile netbeans newbie nls oracle output phone physics print problem program programming project radio recursion scanner screen se server service set size sms socket software sort sql string swing textfield threads time transfer tree trolltech ubuntu utility windows





