Why code return string value is 19880420 instead of 19880320?
SimpleDateFormat template= new SimpleDateFormat("yyyyMMdd");
Calendar cal = Calendar.getInstance();
cal.set(1988, 3, 20, 18, 00);
return template.format(cal.getTime());
Why code return string value is 19880420 instead of 19880320?
SimpleDateFormat template= new SimpleDateFormat("yyyyMMdd");
Calendar cal = Calendar.getInstance();
cal.set(1988, 3, 20, 18, 00);
return template.format(cal.getTime());
Because January is month 0 so you have to do -1 when constructing your calendar http://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#MONTH