SimpleDateFormat dateFormat = new
SimpleDateFormat("yyyyMMdd");//20180603
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
Date dateResult = dateFormat.parse(inputString);
Calendar cal = Calendar.getInstance();
cal.setTime(dateResult);
cal.setTimeZone( TimeZone.getTimeZone("GMT"));
System.out.println(cal.get(Calendar.YEAR)); // 2018
System.out.println(cal.get(Calendar.MONTH)); //05 ?? (instead of 96)
System.out.println(cal.get(Calendar.DAY_OF_MONTH)); // 03
Strangely, when I'm converting a string to date using the above method, the output is 20180503 instead of 2018063. Couldn't find out why this month mismatch occurs. Any suggestions would be appreciated.