We help IT Professionals succeed at work.

Invoke a visual calendar with the current from a date textfield

Vanavah Edwards
on
I have a exellent solution from one of the experts for_van.  But I am unable to get in contact with him.  The date solution 10/23/11 09:30 PM, ID: 37015932from flib and his source code works well and is a solution.  I set this up as a separate class and pass parameters.  However, I still have to return the date to my class in the format I require "mm/dd/yy".  I cant seem to get the actual date in alone my format from the c.getTime() or any other date methods.  Can you help me and that would be the end.  Thanks.
Comment
Watch Question

Awarded 2011
Awarded 2011

Commented:
Awarded 2011
Awarded 2011

Commented:
This is date validation:

import java.text.ParsePosition;
import java.text.SimpleDateFormat;
public class DateValidation {
  
public static boolean validateDate(String inputDate){

          SimpleDateFormat sdf100 = new SimpleDateFormat("MM/dd/yy");
        sdf100.setLenient(false);

     

                java.util.Date dd100 = null;
             boolean goodDate = false;

           try{

         dd100 = sdf100.parse(inputDate, new ParsePosition(0));
                goodDate = true;

           } catch(Exception ex){
                goodDate = false;

           }
         if(dd100 != null && goodDate)return true;
        else return false;

    }


    public static void main(String[] args) {





        SimpleDateFormat sdf100 = new SimpleDateFormat("MM/dd/yy");
        sdf100.setLenient(false);

     

       if(validateDate("25/99/99")){
          System.out.println("25/99/99  is good date!");
        }   else
        {
             System.out.println("25/99/99  is bad date!");
        }


              if(validateDate("12/13/99")){
          System.out.println("12/13/99  is good date!");
        }   else
        {
             System.out.println("12/13/99  is bad date!");
        }

                  if(validateDate("abcd")){
          System.out.println("abcd  is good date!");
        }   else
        {
             System.out.println("abcd  is bad date!");
        }

}
}

Open in new window


Output:

25/99/99  is bad date!
12/13/99  is good date!
abcd  is bad date!

Open in new window

Awarded 2011
Awarded 2011

Commented:

To return date in the format you want you need to foemat it:


SimpleDateFormat sdf100 = new SimpleDateFormat("MM/dd/yy");

java.util.Date dd = new java.util.Date();

String formattedDate = sdf100.format(dd);

formattedDate would be in the format you want .

Author

Commented:
This is not about the data validation that was solved.  My last session is about the code you have me for a visual calendar.  The calendar solution on 10/23/11 09:30 PM, ID: 37015932f downloded from flib.  You source code works well and appear to be a solution.  However, it puts out the selected date from the calendar as "Thu Dec 01 19:08:12 GMT-04:00 2011."  I still have to return the date to my class in the format I require "mm/dd/yy".  I cant seem to get the actual date in my format from the c.getTime() or any other date methods.  Can you help me and that would be the end.  Thanks.
Awarded 2011
Awarded 2011

Commented:
Read my post above - it is strange - you seem to read some posts but not all of them
Awarded 2011
Awarded 2011
Commented:
This is how it works (see output below).

Method getTime() is not for formatting - it returns long number - number of milliseconds
passed since Jan 1, 1970

Class SimpleDateFormat is very useful for formatting ((see code beloow).
http://docs.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormat.html

        SimpleDateFormat sdf100 = new SimpleDateFormat("MM/dd/yy");

        java.util.Date dd2 = new java.util.Date();

        System.out.println("formatted date: " + sdf100.format(dd2));

Open in new window


Output:
formatted date: 12/03/11

Open in new window

Author

Commented:
Your solution works.  There is a time delay between your post and my post when I am responding.  .  I will award your points.
Awarded 2011
Awarded 2011

Commented:

Also go to this:
http://www.experts-exchange.com/Programming/Languages/Java/Q_27476343.html?cid=1131

I posted there some code for you releted to validation of your TextField