HomeLanguagesJavaSimpleDateFormat toPattern() Method in Java with Examples

SimpleDateFormat toPattern() Method in Java with Examples

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

Syntax:  

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




// 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());
    }
}


Output: 

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

 

RELATED ARTICLES

Most Popular

Dominic
32533 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6913 POSTS0 COMMENTS
Nicole Veronica
12029 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12132 POSTS0 COMMENTS
Shaida Kate Naidoo
7043 POSTS0 COMMENTS
Ted Musemwa
7280 POSTS0 COMMENTS
Thapelo Manthata
7000 POSTS0 COMMENTS
Umr Jansen
6986 POSTS0 COMMENTS