SimpleDateFormat format() Method in Java with Examples Last Updated : 01 Dec, 2021 Comments Improve Suggest changes Like Article Like Report 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 Date object type and refers to the date whose string output is to be produced.Return Value: The method returns Date or time in string format of mm/dd/yyyy.Below programs illustrate the working of format() Method of SimpleDateFormat:Example 1: Java // Java code to illustrate format() method import java.text.*; import java.util.Calendar; public class SimpleDateFormat_Demo { public static void main(String[] args) throws InterruptedException { SimpleDateFormat SDFormat = new SimpleDateFormat("MM/dd/yyyy"); // Initializing the calendar Object Calendar cal = Calendar.getInstance(); // Displaying the actual date System.out.println("The original Date: " + cal.getTime()); // Using format() method for conversion String curr_date = SDFormat.format(cal.getTime()); System.out.println("Formatted Date: " + curr_date); } } Output: The original Date: Tue Jan 29 12:23:40 UTC 2019 Formatted Date: 01/29/2019 Example 2: Java // Java code to illustrate format() 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(); // Displaying the actual date System.out.println("The original Date: " + cal.getTime()); // Using format() method for conversion String curr_date = SDFormat.format(cal.getTime()); System.out.println("Formatted Date: " + curr_date); } } Output: The original Date: Tue Jan 29 12:29:32 UTC 2019 Formatted Date: 1/29/19 12:29 PM Comment More infoAdvertise with us Next Article SimpleDateFormat format() 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 parse() Method in Java with Examples The parse() Method of SimpleDateFormat class is used to parse the text from a string to produce the Date. The method parses the text starting at the index given by a start position.Syntax: public Date parse(String the_text, ParsePosition position) Parameters: The method takes two parameters: the_tex 2 min read Float parseFloat() method in Java with examples The parseFloat() method in Float Class is a built in method in Java that returns a new float initialized to the value represented by the specified String, as done by the valueOf method of class Float. Syntax: public static float parseFloat(String s) Parameters: It accepts a single mandatory paramete 2 min read OffsetDateTime format() method in Java with examples The format() method of OffsetDateTime class in Java formats this date-time using the specified formatter. Syntax : public String format(DateTimeFormatter formatter) Parameter : This method accepts a single parameter formatter which specifies the formatter to use, not null.Return Value: It returns th 1 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 OffsetTime format() method in Java with examples The format() method of OffsetTime class in Java formats this time using the specified formatter which is passed in the parameter of the function. Syntax: public String format(DateTimeFormatter formatter) Parameter: This method accepts a single mandatory parameter formatter which specifies the format 2 min read Like