Java DateFormat getInstance() Method with Examples Last Updated : 16 Dec, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 format in a particular format. Example 1: Java // Java program to illustrate // GetInstance() method // importing the required packages import java.text.DateFormat; import java.util.Date; class Testclass { public static void main(String[] args) { // initializing the Date Date d = new Date(); // initializing the DateFormat using getInstance() DateFormat df = DateFormat.getInstance(); // printing the DateFormat return value as object System.out.println("DateFormat Object : " + df); // formatting the current date into a string String str = df.format(d); // printing the current date System.out.println("Current date : " + str); } } OutputDateFormat Object : java.text.SimpleDateFormat@c88bcc54 Current date : 12/15/21, 8:23 AM We can also display the date in the required format using SimpleDateFormat class. Below is the example showing the use of SimpleDateFormat Example 2: Java // Java program to illustrate // GetInstance() method // importing the required packages import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; class Testclass { public static void main(String[] args) { // initializing the Date Date d = new Date(); // initializing the DateFormat using getInstance() DateFormat df = DateFormat.getInstance(); // printing the DateFormat return value as object System.out.println("DateFormat Object : " + df); // formatting the current date into a string String str = df.format(d); // printing the current date System.out.println("Current date : " + str); // initializing the SimpleDateFormat SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy"); // formatting the SimpleDateFormat into a string String st = sdf.format(d); // printing the formatted value System.out.println("Formatted Date : " + st); } } OutputDateFormat Object : java.text.SimpleDateFormat@c88bcc54 Current date : 12/15/21, 8:26 AM Formatted Date : 12-15-2021 Comment More infoAdvertise with us Next Article Java DateFormat getInstance() Method with Examples A akashdeepkatari Follow Improve Article Tags : Java Java-Functions Java-DateFormat Practice Tags : Java Similar Reads 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 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 getDateTimeInstance() 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 Collator getInstance() method in Java with Example The getInstance() method of java.text.Collator class is used to get the new collator object having the current default locale. Syntax: public static Collator getInstance() Parameter: This method does not accept any parameter.Return Value: it provides the new collator object having the current defaul 2 min read Calendar getInstance() Method in Java with Examples The getInstance() method in Calendar class is used to get a calendar using the current time zone and locale of the system. Syntax: public static Calendar getInstance() Parameters: The method does not take any parameters. Return Value: The method returns the calendar. Below program illustrates the wo 1 min read Like