?
Solved

java: processing date variable

Posted on 2008-10-15
4
Medium Priority
?
838 Views
Last Modified: 2013-11-23
I want to create a method that takes in a date variable from the user.  Can someone show me how to do this in Java and then format it so that the final date saved is 10/16/2008.  thanks.
0
Comment
Question by:newbieal
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 4

Author Comment

by:newbieal
ID: 22725443
I want something like this, however the date is supplied by the user:
SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy");
System.out.println("Today is " + df.format(new Date()) );

Open in new window

0
 
LVL 24

Assisted Solution

by:sciuriware
sciuriware earned 60 total points
ID: 22725449
You can use JCalender Bean for date input from http://www.toedter.com/
That saves you a lot of writing.

A Date is saved to a millisecond format.
The format you want is produced when you output only:

Date d;
SimpleDateFormat fmt = new SimpleDateFormat("MM/dd/yyyy");
String result = fmt.format(d);

;JOOP!
0
 
LVL 4

Author Comment

by:newbieal
ID: 22725549
I already have a method in place that passes a string variable that holds the date, but I just don't understand how to use that variable to process it using the code snippet above.
0
 
LVL 6

Accepted Solution

by:
javaexperto earned 90 total points
ID: 22726463
suppose the user call your method like this:
myMethod("12/25/2008");
public void myMethod(String date) {
    /*here you pass the string to the SimpleFomart constructor*/
    SimpleDateFormat df = new SimpleDateFormat(date);
    System.out.println("Today is " + df.format(new Date()) );
}

Open in new window

0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month10 days, 14 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question