SimpleDateFormat toPattern() Method in Java with Examples
Last Updated :
05 Feb, 2021
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
import java.text.*;
import java.util.Calendar;
public class SimpleDateFormat_Demo {
public static void main(String[] args)
throws InterruptedException
{
SimpleDateFormat SDformat
= new SimpleDateFormat();
Calendar cal = Calendar.getInstance();
String Todaysdate
= SDformat.format(cal.getTime());
System.out.println( "Current Date: "
+ Todaysdate);
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
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...