In your code, you are dividing month, day and year with the operator /
.
In Java, there is a class SimpleDateFormat
to format and display dates.
Try the following code:
public String displayDate(int month, int date, int year) {
Calendar calendar = Calendar.getInstance();
calendar.set(year, month, date);
return new SimpleDateFormat("MM/dd/yyyy").format(calendar.getTime());
}
It will return your date in the format MM/dd/yyyy
as a String
.
Note that month
is zero-based.
Check this link out to get some more information about the format: https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html