DateFormat format(Date obj) method in Java Last Updated : 23 Nov, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report The format() method of DateFormat class in Java is used to format a given Date object into a string representing Date/Time.Syntax: String format(Date date) Parameters: This method accepts a single parameter date which is a Date object. Return Value: This method returns a String which is the formatted date-time value of the Date object passed as a parameter to the method. The below programs illustrate the above method: Program 1: Java // Java program to illustrate the // format() method import java.text.DateFormat; import java.util.Date; public class GFG { public static void main(String[] args) { // Create a Date instance Date currentDate = new Date(); // Create a DateFormat instance and format // current Date String dateToStr = DateFormat.getInstance() .format(currentDate); System.out.println("Formatted Date String: " + dateToStr); } } Output:Formatted Date String: 2/27/19 3:31 PM Time complexity: O(1)Auxiliary space: O(1) Program 2: Java // Java program to illustrate the // format() method import java.text.DateFormat; import java.util.*; public class GFG { public static void main(String[] args) { // Create a Date instance Date date = new Date(2323223232L); // Create a DateFormat instance and format // the specified Date String dateToStr = DateFormat.getInstance() .format(date); System.out.println("Formatted Date String: " + dateToStr); } } Output:Formatted Date String: 1/27/70 9:20 PM Time complexity: O(1)Auxiliary space: O(1) Reference: https://docs.oracle.com/javase/7/docs/api/java/text/DateFormat.html#format(java.util.Date)\ Comment More infoAdvertise with us Next Article ChronoLocalDate format() method in Java with Examples G gopaldave Follow Improve Article Tags : Java Java-Functions Java-Date-Time Java-text package Practice Tags : Java Similar Reads DateFormat format() Method in Java with Examples 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 extend 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 ChronoLocalDate format() method in Java with Examples The format() method of ChronoLocalDate interface in Java method formats this date using the specified formatter. Syntax: public String format(DateTimeFormatter formatter) Parameter: This method accepts a parameter obj which specifies the formatter to be used and it is not null. Exceptions: The funct 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 MonthDay format() method in Java with Examples The format() method of MonthDay class in Java formats this month-day using the specified formatter. Syntax: public String format(DateTimeFormatter formatter) Parameter: This method accepts a parameter formatter which specifies the formatter to use and it is not null. Returns: The function returns th 1 min read YearMonth format() method in Java The format() method of YearMonth class in Java is used to format this YearMonth instance according to a specified DateTimeFormatter for year-month passed as parameter to this method. Syntax: public String format(DateTimeFormatter formatter) Parameter: This method accepts a single parameter formatter 1 min read Like