0

i'm trying to make GUI that allowed people to save there shifts in a calendar. i'm trying to build my calendar using import java.uti.Calendar. during trying to print the Month it bring me back the current month 10 instead of 11 , any suggestions?

package hours_report;
import hours_report.MyPanel.MyActionListener;

import java.util.Calendar;
import java.util.Date;

public class MyCalendar {

    private Calendar MyCurrentTime;
    private int currentMonth;


public MyCalendar()
{
    this.MyCurrentTime = Calendar.getInstance();
}

public Date getDate()
{
    return MyCurrentTime.getTime();

}

public int getMonth()
{
    currentMonth = MyCurrentTime.get(MyCurrentTime.MONTH);
    return currentMonth;
}
}


package hours_report;
import javax.swing.*;

public class Tester {

    public static void main(String[] args)
    {
        JFrame frame = new JFrame("Hours Report MI QA");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(600,700);
        MyPanel p = new MyPanel();
        frame.add(p);
        MyCalendar cal = new MyCalendar();
        System.out.println(cal.getDate());
        System.out.println(cal.getMonth());
        frame.setVisible(true);
    }
}
Udi
  • 598
  • 8
  • 19

2 Answers2

1

Months are indexed from 0 not 1 so 10 is November and 11 will be December.

From: Calendar returns wrong month

Community
  • 1
  • 1
JSK NS
  • 3,346
  • 2
  • 25
  • 42
1

The Java Calendar class numbers months from 0 (Jan) to 11 (Dec). You will have to convert this to the conventional 1-12 numbering if that's what you require.

BarrySW19
  • 3,759
  • 12
  • 26