3. write Java whose main method takes a date as an a program called Dateconversi
ID: 3839089 • Letter: 3
Question
3. write Java whose main method takes a date as an a program called Dateconversion call a integer in the format MMDDYYY the user. The main will date conversion (avadoc and method signature is shown below) with the given input and the method will return date in the required format. The month and the e date conversion (12252016) will return December 25, 2016. day will always be given as two digits, zero. 27th will be entered as os272017 and the 1st of July, 2017 will be entered as o7012017. Your Function must deal with the input parameter as an integer throughout your function and not convert it to string.Explanation / Answer
public static String dataConversion(int oldDate) throws ParseException //handling the ParseException cause it may thow exception while parsing the date
{
Calendar calendar = Calendar.getInstance(); //creating calender object
calendar.setTime(new SimpleDateFormat("MMddyyyy").parse(Integer.toString(oldDate))); //Setting input date format to calender object
String newDate = new SimpleDateFormat("MMMM dd, yyyy").format(calendar.getTime()); //Fetching the date in Month day,year format ex: December 15,1990
return newDate;
}
}
Please let me know in comment if you need more explanation on this. Thanks
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.