SimpleDateFormat applyLocalizedPattern() Method in Java with Examples
The applyLocalizedPattern() Method of SimpleDateFormat class is used to apply a localized string pattern to this date format. This pattern can be set by the user.
Syntax:
public void applyLocalizedPattern(String pattern)
Parameters: The method takes one parameter pattern of String type and refers to the new date and time that is to be applied.
Return Value: The method returns void type.
Below programs illustrate the working of applyLocalizedPattern() Method of SimpleDateFormat:
Example 1:
// Java code to illustrate // applyLocalizedPattern() method import java.text.*; import java.util.Calendar; public class SimpleDateFormat_Demo { public static void main(String[] args) throws InterruptedException { SimpleDateFormat SDFormat = new SimpleDateFormat(); // Initializing calender Object Calendar cal = Calendar.getInstance(); // Using the following pattern String new_pat = "MM / dd / yy HH:mm Z" ; // Use of applyLocalizedPattern() SDFormat.applyLocalizedPattern(new_pat); System.out.println( "Applying the format: " + SDFormat .toLocalizedPattern()); } } |
Applying the format: MM / dd / yy HH:mm Z
Example 2:
// Java code to illustrate // applyLocalizedPattern() method import java.text.*; import java.util.*; public class SimpleDateFormat_Demo { public static void main(String args[]) throws Exception { // Initializing SDF SimpleDateFormat SDFormat = new SimpleDateFormat(); // Applying LocalizedPattern SDFormat.applyLocalizedPattern( "dd" ); String str = SDFormat.format( new Date()); // Printing todays date System.out.println( "Today is: " + str); // Applying LocalizedPattern SDFormat.applyLocalizedPattern( "MMM" ); String str1 = SDFormat.format( new Date()); // Printing the month System.out.println( "Month is: " + str1); } } |
Today is: 30 Month is: Jan
Recommended Posts:
- SimpleDateFormat format() Method in Java with Examples
- SimpleDateFormat applyPattern() Method in Java with Examples
- SimpleDateFormat hashCode() Method in Java with Examples
- SimpleDateFormat getDateFormatSymbols() Method in Java with Examples
- SimpleDateFormat setDateFormatSymbols() Method in Java with Examples
- SimpleDateFormat parse() Method in Java with Examples
- SimpleDateFormat equals() Method in Java with Examples
- SimpleDateFormat clone() Method in Java with Examples
- SimpleDateFormat toLocalizedPattern() Method in Java with Examples
- SimpleDateFormat get2DigitYearStart() Method in Java with Examples
- SimpleDateFormat toPattern() Method in Java with Examples
- SimpleDateFormat set2DigitYearStart() Method in Java with Examples
- DecimalFormat applyLocalizedPattern() method in Java
- Java SimpleDateFormat | Set 1
- Java SimpleDateFormat | Set 2
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.