SimpleDateFormat toLocalizedPattern() Method in Java with Examples

The toLocalizedPattern() Method of SimpleDateFormat class is used to return a localized pattern formatted string describing this date format. In other words a particular date is converted to a local pattern such as M/d/yy h:mm a. Syntax:
public String toLocalizedPattern()
Parameters: The method does not take any parameter. Return Value: The method returns localized pattern String of the Date Formatter. Below programs illustrate the working of toLocalizedPattern() Method of SimpleDateFormat: Example 1:Â
Java
// Java code to illustrate// toLocalizedPattern() methodÂ
import java.text.*;import java.util.Calendar;Â
public class SimpleDateFormat_Demo {    public static void main(String[] args)        throws InterruptedException    {        // Initializing date Formatter        SimpleDateFormat SDFormat            = new SimpleDateFormat();Â
        // Initializing the calendar Object        Calendar cal = Calendar.getInstance();Â
        // Displaying the date        System.out.println("Date: "                           + SDFormat.format(                                 cal.getTime()));Â
        // Use of toLocalizedPattern() method        System.out.println("In localized pattern: "                           + SDFormat                                 .toLocalizedPattern());    }} |
Output:
Date: 1/29/19 8:02 AM In localized pattern: M/d/yy h:mm a
Example 2:Â
Java
// Java code to illustrate// toLocalizedPattern() methodÂ
import java.text.*;import java.util.Calendar;Â
public class SimpleDateFormat_Demo {    public static void main(String[] args)        throws InterruptedException    {        // Initializing date Formatter        SimpleDateFormat SDFormat            = new SimpleDateFormat();Â
        // Initializing the calendar Object        Calendar cal = Calendar.getInstance();Â
        // Displaying the date        System.out.println("Date: "                           + SDFormat                                 .format(                                     cal.getTime()));Â
        // Use of toLocalizedPattern() method        System.out.println("In localized pattern: "                           + SDFormat                                 .toLocalizedPattern());    }} |
Output:
Date: 1/29/19 12:46 PM In localized pattern: M/d/yy h:mm a



