Skip to content
Related Articles

Related Articles

SimpleDateFormat toPattern() Method in Java with Examples

Improve Article
Save Article
  • Last Updated : 05 Feb, 2021
Improve Article
Save Article

The toPattern() Method of SimpleDateFormat class is used to return the pattern of the date format.


public String toPattern()

Parameters: The method does not take any parameters.

Return Value: The method returns the pattern string describing this Date format.

Below programs illustrate the working of toPattern() Method of SimpleDateFormat:

Example 1:  


// Java code to illustrate toPattern() method
import java.text.*;
import java.util.Calendar;
public class SimpleDateFormat_Demo {
    public static void main(String[] args)
        throws InterruptedException
        SimpleDateFormat SDformat
            = new SimpleDateFormat();
        // Initializing Calendar object
        Calendar cal = Calendar.getInstance();
        // Getting the Current Date
        String Todaysdate
            = SDformat.format(cal.getTime());
        // Displaying the date
        System.out.println("Current Date: "
                           + Todaysdate);
        // Using toPattern() method
        // to Print the Date Pattern
        System.out.println("The Date Pattern- "
                           + SDformat.toPattern());


Current Date: 1/29/19 6:05 AM
The Date Pattern- M/d/yy h:mm a


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!