Results 1 to 2 of 2
  1. #1
    vasu18 is offline Member
    Join Date
    Dec 2007
    Posts
    3
    Rep Power
    0

    Default Java Calendar Class

    Hi..all..

    I am new to java,

    I want to display previous six months from the current month,i am using th following code
    Calendar cal = Calendar.getInstance();

    String[] monName = {"January", "February","March", "April", "May", "June", "July",
    "August", "September", "October", "November","December"};

    String mon1 = monName[cal.get(Calendar.MONTH)];
    String mon2 = monName[(cal.get(Calendar.MONTH)-1)];
    String mon3 = monName[(cal.get(Calendar.MONTH)-2)];
    String mon4 = monName[(cal.get(Calendar.MONTH)-3)];
    String mon5 = monName[(cal.get(Calendar.MONTH)-4)];
    String mon6 = monName[(cal.get(Calendar.MONTH)-5)];
    String mon7 = monName[(cal.get(Calendar.MONTH)-6)];


    System.out.println(mon1);
    System.out.println(mon2);
    System.out.println(mon3);
    System.out.println(mon4);
    System.out.println(mon5);
    System.out.println(mon6);
    System.out.println(mon7);

    output should be December,november,october,september,august,july,ju ne

    it is working fine in my local machine..
    But in the production server,i am getting the current month as november,november,october,september,august,july,ju ne,may

    i dont know..why..it happens..
    can any one..help me

  2. #2
    CaptainMorgan's Avatar
    CaptainMorgan is offline Moderator
    Join Date
    Dec 2007
    Location
    NewEngland, US
    Posts
    835
    Rep Power
    8

    Default

    I don't see a problem with your logic... worked fine on my system too. Verify locale configuration and Java version on your production server.
    Last edited by CaptainMorgan; 12-22-2007 at 03:55 AM.

Similar Threads

  1. How to use Calendar class
    By JavaBean in forum Java Tip
    Replies: 1
    Last Post: 06-26-2008, 04:09 PM
  2. How to use Calendar class
    By Java Tip in forum java.util
    Replies: 0
    Last Post: 04-04-2008, 03:33 PM
  3. java Date and Calendar
    By valoyivd in forum New To Java
    Replies: 1
    Last Post: 03-30-2008, 07:49 PM
  4. Java Calendar Class
    By vasu18 in forum New To Java
    Replies: 0
    Last Post: 12-06-2007, 11:45 AM
  5. Replies: 1
    Last Post: 08-07-2007, 08:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •