5 Replies Latest reply on Oct 8, 2006 10:55 AM by 807598

    getting date

      Hi Techies,
      I am trying to get the number of days in a month. Here is my code
       int totalNumberOfDaysInTheCurrentMonth =calendar.getActualMaximum(calendar.DAY_OF_MONTH);
               Date endOfTheMonthDate = new Date(totalNumberOfDaysInTheCurrentMonth);
      I am getting 31 for october but I need to get in mm/dd/yyyy format. How can i do this one.

        • 1. Re: getting date
          You're not making sense. The number of days in a month is an integer. It doesn't have a "mm/dd/yyyy" format.

          Are you trying to say that you're trying to get a formatted date string representing the last day of a month?

          In that case, set the date in the calendar to the last day of the month, get a Date object from the Calendar, and then pass the Date object to a java.text.SimpleDateFormat.
          • 2. Re: getting date
            thanks for your suggestion.
            can you please send me the sample code
            • 3. Re: getting date
              No. What part of what I said didn't you understand?
              • 4. Re: getting date
                thanks , I got the solution;
                DateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
                           int month =calendar.get(calendar.MONTH);
                           int year = calendar.get(calendar.YEAR);
                         int totalNumberOfDaysInTheCurrentMonth =calendar.getActualMaximum(calendar.DAY_OF_MONTH);
                          Date d =calendar.getTime();
                but I wonder why month is giving me 9 instead of 10.
                • 5. Re: getting date
                  Months are zero-indexed. January is month number zero.