We would like to know how to format Calendar with FieldPosition.
import java.text.FieldPosition; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.GregorianCalendar; //from w w w . j a v a 2 s . c o m public class Main { public static void main (String args[]) { int days = 1; int month = 1; int year = 2001; SimpleDateFormat sdf = new SimpleDateFormat("E dd-MM-yyyy G"); StringBuffer buf = new StringBuffer(); Calendar cal = new GregorianCalendar(); cal.set(year, month-1, days); sdf.format(cal.getTime(), buf, new FieldPosition(10)); System.out.println(buf.toString()); } }
The code above generates the following result.