Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Calendar class is giving me problems!

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Calendar class is giving me problems!

    I'm trying to generate a list of date between date1 and date2, without success.
    What am i doing wrong? Here's my code:
    -----------------------------------------------------------------------------
    private static void dateRange()
         {
             Calendar c1 = new GregorianCalendar();
             c1.set(2011,01,01);
             Calendar c2 = new GregorianCalendar();
             c2.set(2011,12,31);
     
             while(!c1.equals(c2))
             {
                SimpleDateFormat sdf = new SimpleDateFormat("MMyyyy");
                String date = sdf.format(c1.getTime());
                System.out.println(date);  
                c1.add(Calendar.DATE,1);
             }
         }
    ---------------------------------------------------------------------------------------
    Last edited by pbrockway2; December 28th, 2012 at 02:51 AM. Reason: code tags added


  2. #2
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default Re: Calendar class is giving me problems!

    What am i doing wrong?
    Perhaps it would be a good idea to explain in what way the program behaviour is not what you expect or intend. Rewrite your example as the main() method of some class we can all run. And describe both the behaviour you observe and the behaviour you expect or intend. It might make things simpler if the dates aren't so far apart (ie it will reduce output).

    ---

    In any case you should have a read of the set() API documentation to make sure the arguments you are supplying are those you mean to supply.

Similar Threads

  1. Java, calling another public class from within the main class giving problems.
    By RandomGaisha in forum What's Wrong With My Code?
    Replies: 9
    Last Post: November 26th, 2012, 02:30 PM
  2. [SOLVED] Calendar class question.
    By banny7 in forum Algorithms & Recursion
    Replies: 2
    Last Post: September 11th, 2012, 12:44 PM
  3. Gregorian Calendar - Problems
    By BobDole6395 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: July 9th, 2012, 02:24 PM
  4. Class hierarchy... giving me a headache, so I could use some help
    By Kerr in forum Object Oriented Programming
    Replies: 6
    Last Post: May 30th, 2011, 05:03 PM
  5. I'm having trouble with date and calendar class
    By kiph in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 7th, 2010, 02:56 AM

Tags for this Thread