Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date input

Status
Not open for further replies.

robmif76

Programmer
Feb 1, 2003
10
0
0
GB
Hi all,

i am a Java newbie and I need some help in geting user date input using the calendar class.


Any help?
 
Sure, we can provide help. What are you trying to do, EXACTLY?
 
Well, basically I'm trying to find out the most convenient way of gathering a date (dd/mm/yyyy) user input using the buffered reader.

Cheers
 
Code:
SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy");
DateFormat df2 = DateFormat.getDateInstance(DateFormat.FULL);
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String input;
System.out.print("Enter date as MM/dd/yyyy:");
input = reader.readLine();
try {
    Date d = df.parse(input);
    System.out.println("The date you entered is:" +       df2.format(d));

} catch (Exception e) {
    System.err.println("The value you entered is not a date!");
}
 
Thanks alot mate.

That certainly sorted out my problem!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top