Java Format - 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;
//  w w  w.j  a  v  a2 s .  c  o m
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.