The format() Method of DateFormat class in Java 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 i.e., mm/dd/yyyy.
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 DateFormat:
The original Date: Wed Mar 27 11:12:29 UTC 2019 Formatted Date: Mar 27, 2019
The original Date: Wed Mar 27 11:12:37 UTC 2019 Formatted Date: March 27, 2019 11:12:37 AM UTC
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.