Currently, i'm trying to format my date into a specific format:
here is my method that returns a date:
public Date createDate(int year, int month, int day) {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, year);
cal.set(Calendar.MONTH, month);
cal.set(Calendar.DAY_OF_MONTH, day);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return sdf.format(cal. getTime());
}
my format:
private String myFormat = "MM/dd/yyyy"; //In which you need put here
private SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.US);
now the problem is when i try to use sdf.format(cal.getTime());
it says that it is incompatible type because it found a string when i try to use the sdf.format.
would it be possible to use the format the date into the format i want without converting it to string?