i want to convert the value of my date into an integer value, i am using a jDateChooser in netbeans(swings)
currently in my code below the value for inputDate is fixed or assingned but i want it to be based on the date a user picks using the jDateChooser.

 public void OnDateClick(){
        int inputDate = 20121220 ;//variable name for my  jDateChooser is "OnDateClick" which i want assign to inputDate
        DateFormat df = new SimpleDateFormat("yyyyMMdd");
        String date = df.format(Integer.valueOf(inputDate));

        String s = date.format(date);
        int output = Integer.valueOf(s);
        System.out.println(s);
    }

I will appreciate the help thank you.

and why would exactly do you want this?
are you planning to perform heavy mathematical instructions on your dates?

and what is it you are having trouble with? getting the date from the datepicker, or converting it into an int?

exactly i want perform some maths with the integer value i get from my datepicker.

and i am hiving trouble with assigning my jdatechooser to the inputDate variable.

i want to convert the date i pick into an integer and use that integer value in my math calculations.
i hope it is clear now? thans

java.util.Date objects always have a numeric representation.

Perhaps you need something more like this:

        DateFormat df = new SimpleDateFormat("yyyyMMdd");
        Date date = df.parse(inputDate);
        System.out.println("Java Date = " + date.toString());
        System.out.println("Java Date as a 'long' value = " + date.getTime());  // Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object.
        System.out.println("Number of days since Jan 1st, 1970 = " + date.getTime() / (24 * 60 * 60 * 1000));  // number of days since January 1, 1970

i don't if my question is clear but i have a jDateChooser on my app. so when i pick a date, that date should be converted to an integer. so let say i pick 1-2-2013, this date should be converted to an interger.

thank your help and patience

yes, but why? to what use? what "maths" are you trying to perform on it?
if need be, just get the date, month and year, concatenate them all together to a String and parse it to an int.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.