0

I want to map an index from my 3D array to a date. I have an array (sortedData[34][12][31]) and I would like to have it so that if a date is selected from JCalendar it corresponds to the correct index in my array. E.g. say the date 01/01/1974 is selected I would like it to map to sortedData[0][0][0].

How would I go about doing this? Thanks.

JmJ
  • 1,989
  • 3
  • 29
  • 51

1 Answers1

1

Use a java.util.Calendar object to get the day, month and year of the date:

Calendar calendar = new GregorianCalendar();
calendar.setTime(theDate);
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int day = calendar.get(Calendar.DAY_OF_MONTH);

Then get the indices in your array using

int i = year - 1974;
int j = month;
int k = day;
JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255