Java DateFormat.format(Date date)

Syntax

DateFormat.format(Date date) has the following syntax.

public final String format(Date date)

Example

In the following code shows how to use DateFormat.format(Date date) method.


//from   ww w .jav a2s.  com
import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;

public class Main {
  public static void main(String[] argv) throws Exception {
    DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG,
        DateFormat.LONG,Locale.getDefault());
    
    
    String s = dateFormat.format(new Date());
    System.out.println(s);

  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.text »




DateFormat
DecimalFormat
NumberFormat
SimpleDateFormat