SimpleDateFormat applyPattern() Method in Java with Examples Last Updated : 08 Jul, 2021 Comments Improve Suggest changes Like Article Like Report The applyPattern() Method of SimpleDateFormat class is used to set a given defined pattern to the Date Format. It simply converts a particular date and time to a specific format as defined by the user for eg., dd/ MM/ yyyy HH:mm Z or MM/ dd/ yyyy HH:mm Z.Syntax: public void applyPattern(String pattern) Parameters: The method takes one parameter pattern of String type and refers to the new date and time pattern for this date format.Return Value: The method returns void type.Below programs illustrate the working of applyPattern() Method of SimpleDateFormat:Example 1: Java // Java code to illustrate // applyPattern() 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 the calendar Object Calendar cal = Calendar.getInstance(); // Using the below pattern String new_pat = "dd/ MM/ yyyy HH:mm Z"; // Use of applyPattern() method SDFormat.applyPattern(new_pat); // Displaying Current date and time String curr_date = SDFormat.format(cal.getTime()); System.out.println("The Current Date: " + curr_date); // Displaying the pattern System.out.println("Applied Pattern: " + SDFormat.toPattern()); } } Output: The Current Date: 29/ 01/ 2019 07:22 +0000 Applied Pattern: dd/ MM/ yyyy HH:mm Z Example 2: Java // Java code to illustrate // applyPattern() 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 the calendar Object Calendar cal = Calendar.getInstance(); // Using the below pattern String new_pat = "MM/ dd/ yyyy HH:mm Z"; // Use of applyPattern() method SDFormat.applyPattern(new_pat); // Displaying Current date and time String curr_date = SDFormat.format(cal.getTime()); System.out.println("The Current Date: " + curr_date); // Displaying the pattern System.out.println("Applied Pattern: " + SDFormat.toPattern()); } } Output: The Current Date: 01/ 29/ 2019 07:22 +0000 Applied Pattern: MM/ dd/ yyyy HH:mm Z Comment More infoAdvertise with us Next Article SimpleDateFormat applyPattern() Method in Java with Examples C chinmoy lenka Follow Improve Article Tags : Misc Java Java-Functions Java-text package Java-SimpleDateFormat +1 More Practice Tags : JavaMisc Similar Reads 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 2 min read SimpleDateFormat format() Method in Java with Examples The format() Method of SimpleDateFormat class is used to format a given date into Date/Time string. Basically the method is used to convert this date and time into a particular format for say mm/dd/yyyy.Syntax: public final String format(Date date) Parameters: The method takes one parameter date of 2 min read MessageFormat applyPattern() method in Java with Example The applyPattern() method of java.text.MessageFormat class is used to set the new pattern text for current MessageFormat by overriding the current FormatElement, FormatType and FormatStyle. Syntax: public void applyPattern(String newPattern) Parameter: This method takes string newPattern as paramete 2 min read SimpleDateFormat toPattern() Method in Java with Examples The toPattern() Method of SimpleDateFormat class is used to return the pattern of the date format. Syntax: public String toPattern() Parameters: The method does not take any parameters. Return Value: The method returns the pattern string describing this Date format. Below programs illustrate the wor 1 min read NumberFormat clone() method in Java with Examples The clone() method is a built-in method of the java.text.NumberFormat returns a object which defines the clone of any given instance. Syntax: public Object clone() Parameters: The function does not accepts any parameter. Return Value: The function returns a object which defines the clone of any give 1 min read Like