You could try something like this
@Test
public void formatDate() {
Date today = new Date();
SimpleDateFormat fourDigitsYearOnlyFormat = new SimpleDateFormat("yyyy");
FieldPosition yearPosition = new FieldPosition(DateFormat.YEAR_FIELD);
DateFormat dateInstanceUK = DateFormat.getDateInstance(DateFormat.SHORT,
Locale.UK);
StringBuffer sbUK = new StringBuffer();
dateInstanceUK.format(today, sbUK, yearPosition);
sbUK.replace(yearPosition.getBeginIndex(), yearPosition.getEndIndex(),
fourDigitsYearOnlyFormat.format(today));
System.out.println(sbUK.toString());
DateFormat dateInstanceUS = DateFormat.getDateInstance(DateFormat.SHORT,
Locale.US);
StringBuffer sbUS = new StringBuffer();
dateInstanceUS.format(today, sbUS, yearPosition);
sbUS.replace(yearPosition.getBeginIndex(), yearPosition.getEndIndex(),
fourDigitsYearOnlyFormat.format(today));
System.out.println(sbUS.toString());
}
It basically formats the date using the style DateFormat#SHORT and catches the location of the year using a FieldPosition object. After that you replace the year with its four digits formart.
Output is:
13/11/2013
11/13/2013
EDIT
Use with any pattern
StringBuffer sb = new StringBuffer();
DateFormat dateInstance = new SimpleDateFormat("yy-MM-dd");
System.out.println(dateInstance.format(today));
dateInstance.format(today, sb, yearPosition);
sb.replace(yearPosition.getBeginIndex(), yearPosition.getEndIndex(),
fourDigitsYearOnlyFormat.format(today));
System.out.println(sb.toString());
Output is:
13-11-13
2013-11-13