Java Format - Java DateFormat.format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition)








Syntax

DateFormat.format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) has the following syntax.

public abstract StringBuffer format(Date date,   StringBuffer toAppendTo,   FieldPosition fieldPosition)

Example

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

import java.text.DateFormat;
import java.text.FieldPosition;
import java.util.Date;
//from   w ww . jav  a 2  s.c om
public class Main {
  public static void main(String[] argv) throws Exception {
    DateFormat dateFormat = DateFormat.getDateInstance();
    StringBuffer sb = new StringBuffer();
    
    sb = dateFormat.format(new Date(),sb,new FieldPosition(DateFormat.DAY_OF_WEEK_IN_MONTH_FIELD));
    System.out.println(sb);

  }
}

The code above generates the following result.