Link to home
Start Free TrialLog in
Avatar of Vanavah Edwards
Vanavah Edwards

asked on

Invoke a visual calendar with the current from a date textfield

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.
Avatar of for_yan
for_yan
Flag of United States of America image

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


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 .
Avatar of Vanavah Edwards
Vanavah Edwards

ASKER

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.
Read my post above - it is strange - you seem to read some posts but not all of them
ASKER CERTIFIED SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Your solution works.  There is a time delay between your post and my post when I am responding.  .  I will award your points.

Also go to this:
https://www.experts-exchange.com/questions/27476343/Date-formatter-field-with-built-in-method-testing.html?cid=1131

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