Java SimpleDateFormat applyLocalizedPattern() Example
SimpleDateFormat class applyLocalizedPattern() method example. This example shows you how to use applyLocalizedPattern() method.
Syntax is : public void applyLocalizedPattern(String pattern)
This method applies the given localized pattern string to this date format.
Here is the code.
/**
* @(#) ApplyLocalizedPatternSimpleDateFormat.java
* A class representing use of method applyLocalizedPattern() of
* SimpleDateFormat class in java.text Package.
* @Version 13-May-2008
* @author Rose India Team
*/
import java.util.*;
import java.text.*;
class ApplyLocalizedPatternSimpleDateFormat {
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 in dafault pattern : " + dateFormat);
// applyLocalizedPattern method call.
sdf.applyLocalizedPattern("hh:mm:ss");
dateFormat = sdf.format(date);
System.out.println("Date in hh:mm:ss pattern : " + dateFormat);
sdf.applyLocalizedPattern("E MMM dd yyyy");
dateFormat = sdf.format(date);
System.out.println("Date in E MMM dd yyyy pattern : " + dateFormat);
}
} |
Output of the program.
Date by Date class : Fri Jun 13 18:52:15 GMT+05:30 2008
Date in dafault pattern : 6/13/08 6:52 PM
Date in hh:mm:ss pattern : 06:52:15
Date in E MMM dd yyyy pattern : Fri Jun 13 2008 |
|