DateFormat format(Date obj) method in Java
The format() method of DateFormat class in Java is used to format a given Date object into a string representing Date/Time.
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.
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.
Below programs illustrate the above method:
Formatted Date String: 2/27/19 3:31 PM
Formatted Date String: 1/27/70 9:20 PM