Java SimpleDateFormat.toPattern()

Syntax

SimpleDateFormat.toPattern() has the following syntax.

public String toPattern()

Example

In the following code shows how to use SimpleDateFormat.toPattern() method.


import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Locale;
//from  www . jav  a2 s. c om
public class Main {
  public static void main(String args[]) {
    SimpleDateFormat df = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT);
    System.out.println("The short date format is  " + df.toPattern());
    Locale loc = Locale.ITALY;
    df = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, loc);
    System.out.println("The short date format is  " + df.toPattern());
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.text »




DateFormat
DecimalFormat
NumberFormat
SimpleDateFormat