I have played with this for almost 6 hours now and looked at other questions but can't seem to figure out what I'm doing wrong that is giving me these odd results. Here is my code below
String dateStr = "20171230";
StringBuilder sb = new StringBuilder();
sb.append(dateStr.subSequence(0, 4))
.append("/")
.append(dateStr.substring(4,6))
.append("/")
.append(dateStr.substring(6,8));
dateStr = sb.toString();
System.out.println("date string is " + dateStr);
DateFormat df = new SimpleDateFormat("yyyy/mm/dd");
df.setLenient(false);
Date Date = null;
try {
Date = df.parse(dateStr);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Date is " + Date);
output is
date string is 2017/12/30
Date is Mon Jan 30 00:12:00 CST 2017
The date should be December 30, not January 30. Can someone tell my why this is happening.