java.text.SimpleDateFormat toLocalizedPattern()

Description :

This java example shows how to use the toLocalizedPattern()  method of SimpleDateFormat class of java.text package. This method returns a localized pattern string describing this date format..

Method Syntax :

public String toLocalizedPattern()

Parameter Input :

 

DataType Parameter Description
N/A N/A N/A

 

Method Returns :

This method returns a localized pattern string describing this date format.

Compatibility Version :

Requires Java 1.2 and up

Exception :

N/A

Java Code Example :

This java example source code demonstrates the use of toLocalizedPattern() method of SimpledDateFormat class. The code just prints the date current localized pattern being used by the Formatter. This is preferred method over the toPattern() if you are dealing with multiple locale.

package com.javatutorialhq.java.examples;

import java.text.SimpleDateFormat;
import java.util.Calendar;


/*
 * This example source code demonstrates the use of  
 * toLocalizedPattern() method 
 * of SimpleDateFormat class
 */

public class SimpleDateFormatToPatternExample {

	public static void main(String[] args) {
		
		// Initialize the formatter
		SimpleDateFormat sdf = new SimpleDateFormat();
		
		// initialize calendar object
		Calendar cal = Calendar.getInstance();
		
		// get the current date and time
		String dateToday = sdf.format(cal.getTime());
		
		// get the localized pattern used by the formatter
		String locPattern = sdf.toLocalizedPattern();
		
		// printing date today
		System.out.println("Date today:"+dateToday);
		
		// printing the pattern used
		System.out.println("Pattern:"+locPattern);
	}

}

Sample Output :

Running the toLocalizedPattern() method example source code of Calendar class will give you the following output:

SimpleDateFormat toLocalizedPattern method example

SimpleDateFormat toLocalizedPattern method example

Exception Scenario :

There are no notable exception that can be thrown by this method

Similar Method :

  • N/A

Suggested Reading List :

References :