I try to convert a String to GregorianCalendar, and then check it. Below, I post my codes. I really confuse that why the fields seem wrong. Thanks a lot for help.
public class test{ private static final ArrayList<String> MONTH_OF_YEAR = new ArrayList(Arrays.asList( "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")); static GregorianCalendar date; public static void main(String[] args){ String t = "28-Mar-2099 11294.94 11279.65"; String[] splitStr = t.split(" "); System.out.println(splitStr[0]); date = ConvertToDate(splitStr[0]); System.out.println(date.getTime()); System.out.println(date.DAY_OF_MONTH); System.out.println(date.MONTH); System.out.println(date.YEAR); } private static GregorianCalendar ConvertToDate(String dt){ String[] splitStr = dt.split("-"); if(splitStr.length != 3){ throw new IllegalArgumentException(); } int dayOfMonth = Integer.parseInt(splitStr[0]); int year = Integer.parseInt(splitStr[2]); int month = MONTH_OF_YEAR.indexOf(splitStr[1]); if(month < 0 || month > 11){ throw new IllegalArgumentException(); } return new GregorianCalendar(year, month, dayOfMonth); } } And the outputs are like these:
28-Mar-2099 Sat Mar 28 00:00:00 PDT 2099 5 2 1 Could anyone help me explain why that the fields don't match the date?