DateFormat format() Method in Java with Examples Last Updated : 22 Jun, 2022 Comments Improve Suggest changes Like Article Like Report DateFormat class present inside java.text package is an abstract class that is used to format and parse dates for any locale. It allows us to format date to text and parse text to date. DateFormat class provides many functionalities to obtain, format, parse default date/time. DateFormat class extends Format class that means it is a subclass of Format class. Since DateFormat class is an abstract class, therefore, it can be used for date/time formatting subclasses, which format and parses dates or times in a language-independent manner. The format() method of DateFormat class in Java is used to format a given date into a Date/Time string. Basically, the method is used to convert this date and time into a particular format i.e., mm/dd/yyyy. Syntax: public final String format(Date date) Parameters: The method takes one parameter date of the Date object type and refers to the date whose string output is to be produced. Return Type: Returns Date or time in string format of mm/dd/yyyy. Example 1: Java // Java Program to Illustrate format() Method // of DateTime Class // Importing required classes import java.text.*; import java.util.Calendar; // Main class // DateFormat_Demo public class GFG { // Main driver method public static void main(String[] args) { // Initializing the first formatter DateFormat DFormat = DateFormat.getDateInstance(); // Initializing the calendar Object Calendar cal = Calendar.getInstance(); // Displaying the actual date System.out.println("The original Date: " + cal.getTime()); // Converting date using format() method String curr_date = DFormat.format(cal.getTime()); // Printing the formatted date System.out.println("Formatted Date: " + curr_date); } } Output: The original Date: Wed Mar 27 11:12:29 UTC 2019 Formatted Date: Mar 27, 2019 Example 2: Java // Java Program to Illustrate format() Method // of DateTime Class // Importing required classes import java.text.*; import java.util.*; // Main class // DateFormat_Demo public class GFG { // Main driver method public static void main(String[] args) { // Initializing the first formatter DateFormat DFormat = DateFormat.getDateTimeInstance( DateFormat.LONG, DateFormat.LONG, Locale.getDefault()); // Initializing the calendar Object Calendar cal = Calendar.getInstance(); // Displaying the actual date System.out.println("The original Date: " + cal.getTime()); // Converting date using format() method and // storing date in a string String curr_date = DFormat.format(cal.getTime()); // Printing the formatted date on console System.out.println("Formatted Date: " + curr_date); } } OutputThe original Date: Tue Jan 11 05:42:29 UTC 2022 Formatted Date: January 11, 2022 at 5:42:29 AM UTC Comment More infoAdvertise with us Next Article DateFormat format() Method in Java with Examples chinmoy lenka Follow Improve Article Tags : Misc Java Java - util package Java-Functions Java-DateFormat +1 More Practice Tags : JavaMisc Similar Reads ChoiceFormat format() method in Java with Examples The format() method of java.text.ChoiceFormat class is used to get the appended string builder of the format value of particular limit value passed as parameter and text passed as parameter in this method. Syntax: public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition statu 2 min read Date from() method in Java with Examples The from(Instant inst) method of Java Date class returns an instance of date which is obtained from an Instant object. Syntax: public static Date from(Instant inst) Parameters: The method takes one parameter inst of Instant type which is required to be converted. Return Value: The method returns a d 2 min read DateFormat hashCode() method in Java with Examples The hashCode() Method of DateFormat class is used to return the hash code value of this DateFormat object. The hash code is of integer type. Syntax: public int hashCode() Parameters: The method does not take any parameters. Return Value: The method returns the hash code value of this DateFormat obje 2 min read Java DateFormat getInstance() Method with Examples The getInstance() method of DateFormat class will return the date and time formatter with the default formatting style for the default locale. Syntax: public static final DateFormat getInstance() Parameter: This method doesn't require any parameters. Return value: This method will return the date fo 2 min read DateFormat getCalendar() Method in Java with Examples The getCalendar() Method of DateFormat class in Java is used to get the calendar associated with this date/time format object. Syntax: public Calendar getCalendar() Parameter: The method does not take any parameters. Return Value: The method returns an instance of Calendar for this DateFormat object 2 min read DateFormat equals() Method in Java with Examples The equals() Method of the DateFormat class is used to compare two DateFormat objects. The method returns True if this DateFormat is equal to the passed object else returns False. Syntax: public boolean equals(Object obj) Parameters: The method takes one parameter obj of Object type and refers to th 2 min read DateFormat getTimeZone() Method in Java with Examples The getTimeZone() method in DateFormat class is used to return the current time-zone of the calendar of this DateFormat. Syntax: public TimeZone getTimeZone() Parameters: The method does not take any parameters. Return Value: The method returns timezone associated with the calendar of DateFormat. Be 1 min read DateFormat isLenient() Method in Java with Examples The isLenient() method in DateFormat class is used to know and understand whether the parsing of date and time of this DateFormat object is to be considered lenient or not. Syntax: public boolean isLenient() Parameters: The method does not take any parameters. Return Value: The method either returns 2 min read DateFormat getDateInstance() Method in Java with Examples DateFormat class of java.text package is an abstract class that is used to format and parse dates for any locale. It allows us to format date to text and parse text to date. DateFormat class provides many functionalities to obtain, format, parse default date/time. Note: DateFormat class extends Form 2 min read DateFormat getTimeInstance() Method in Java with Examples DateFormat class of java.text package is an abstract class that is used to format and parse dates for any locale. It allows us to format date to text and parse text to date. DateFormat class provides many functionalities to obtain, format, parse default date/time. Note: DateFormat class extends Form 2 min read Like