I have a situation where i can get only the date like 9/2/2016. From this, i need to parse and create a pattern like M/D/YYYY. From this i can convert the any input date to the above pattern M/D/YYYY.
Is there any utility/API for that in java.?
I have a situation where i can get only the date like 9/2/2016. From this, i need to parse and create a pattern like M/D/YYYY. From this i can convert the any input date to the above pattern M/D/YYYY.
Is there any utility/API for that in java.?
For your requirement, first you parse the input string with appropriate format. Then you do format the date. For more info refer SimpleDateFormat
SimpleDateFormat dateFormat = new SimpleDateFormat("M/d/yyyy");
Date myDate = dateFormat.parse("9/2/2016");
SimpleDateFormat dateFormat2 = new SimpleDateFormat("MM/dd/yyyy");
System.out.println(dateFormat2.format(myDate));
Output
09/02/2016
You can use SimpleDateFormat to do this.
SimpleDateFormat dateFormat = new SimpleDateFormat(MM/dd/yyyy);
https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html