Java Format - Java SimpleDateFormat.format(Date date, StringBuffer toAppendTo, FieldPosition pos)








Syntax

SimpleDateFormat.format(Date date, StringBuffer toAppendTo, FieldPosition pos) has the following syntax.

public StringBuffer format(Date date,   StringBuffer toAppendTo,   FieldPosition pos)

Example

In the following code shows how to use SimpleDateFormat.format(Date date, StringBuffer toAppendTo, FieldPosition pos) method.

import java.text.DateFormat;
import java.text.FieldPosition;
import java.text.SimpleDateFormat;
import java.util.Date;
//from  w w  w  . j  a va 2s . c om
public class Main {
  public static void main(String[] argv) throws Exception {

    SimpleDateFormat formatter = new SimpleDateFormat();

    StringBuffer sb = new StringBuffer();
    formatter.format(new Date(), sb, new FieldPosition(DateFormat.DATE_FIELD));
    System.out.println(sb);
  }
}

The code above generates the following result.