Java SimpleDateFormat toLocalizedPattern() Example
SimpleDateFormat class toLocalizedPattern() method example. This example shows you how to use toLocalizedPattern() method.
Syntax is : public String toLocalizedPattern()
This method returns a localized pattern string describing this date format.
Here is the code.
/**
* @(#) ToLocalizedPatternSimpleDateFormat.java
* A class representing use of method toLocalizedPattern() of SimpleDateFormat
class in java.text Package.
* @Version 14-May-2008
* @author Rose India Team
*/
import java.util.*;
import java.text.*;
class ToLocalizedPatternSimpleDateFormat {
public static void main(String[] args) {
// Create new Date object that will be initialized to the current date.
Date date = new Date();
System.out.println("Date by Date class : "+date.toString());
SimpleDateFormat sdf;
// Create new SimpleDateFormat object that returns default pattern.
sdf = new SimpleDateFormat();
String dateFormat = sdf.format(date);
System.out.println("Date by SimpleDateFormat class : " + dateFormat);
// toLocalizedPattern method call for SimpleDateFormat object.
String pattern = sdf.toLocalizedPattern();
System.out.println("Localized pattern string : " + pattern);
}
} |
Output of the program.
Date by Date class : Sat Jun 14 13:18:18 GMT+05:30 2008
Date by SimpleDateFormat class : 6/14/08 1:18 PM
Localized pattern string : M/d/yy h:mm a |
|