Convert string to date in java

try {

Date date = new Date();
Calendar cal = Calendar.getInstance();

cal.set(2017, 04, 08);
int startYear = cal.get(Calendar.YEAR);
int startMonth = cal.get(Calendar.MONTH);
int startDay = cal.get(Calendar.DAY_OF_MONTH);

System.out.println(“date year ” + startYear);
System.out.println(“date month ” + startMonth);
System.out.println(“date day ” + startDay);

cal.setTime(date);
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
int day = cal.get(Calendar.DAY_OF_MONTH);

System.out.println(“date year ” + year);
System.out.println(“date month ” + month);
System.out.println(“date day ” + day);

}

Leave a Reply

Your email address will not be published. Required fields are marked *